I have a shortcode that I want to run on the single template from the cloud library. I tried running get_the_ID() and it returns the ID of the cloud template page, not the post that is being rendered by the single template. How can I get the ID of the page being rendered so I can properly pull custom data in?
Hello @wordpressive!
The post’s ID can be found when you hover over the “Edit button”: https://app.screencast.com/ASvBMdTmVNMCn
The same you can do for the Single template that you use: https://app.screencast.com/VSxyaMAL4aiRp
I hope that helps you!
Thank you!
Sorry, my question wasn’t clear.
I’m running custom code, inside a shortcode I put on the template.
So I added [my_shortcode] to single cloud template.
[my_shortcode] when it executes needs the ID of the post being rendered. But when I call the WordPress function get_the_ID() it returns the ID of the single cloud template instead. Which means I can’t get the proper data to manipulate and display.
How can I programmatically get the ID of the post with code executing in this context?
Hello @wordpressive!
For customization and other services, you can contact our custom work team here: https://tagdiv.com/premium-customization-services/.
Thank you so much for your understanding!
I’m a developer, I’m asking what API/function calls work to get the ID of the post being rendered within the context of an external shortcode executing on a cloud template.
get_the_ID() returns the ID of the single template page. How does one get the ID of the page being rendered by the single template page?
Hello @wordpressive!
$post_id = null;
if( tdb_state_template::get_template_type() == 'single' || tdb_state_template::get_template_type() == 'cpt' ) {
global $tdb_state_single;
$post_id = $tdb_state_single->post_id->__invoke();
}
Thank you!