Thank you for confirming that.
I am trying to get the page ID in my plugin. I seem unable to access the the_ID() function whether I set global $wp_query; or not.
I have tried a number of methods suggested on different wordpress pages but cannot get a definitive answer.
I use "pretty" permalinks and am told that 'the_ID();' does not work with them. A solution suggested was:
global $wp_query;
$page_object = $wp_query->get_queried_object();
$page_id = $wp_query->get_queried_object_id();
I got the error:
Fatal error: Call to a member function get_queried_object() on a non-object in /var/www/...
Further I have tried the following for inside and outside of the loop, respectively:
function function_name() {
global $post;
$thePostID = $post->ID;
}
function function_name() {
global $wp_query;
$thePostID = $wp_query->post->ID;
}
Please can anyone help or provide a reason as to why there is an issue. Alternatively, how to get the page id under any circumstance when called from a plugin function.
Many thanks.