I am trying to get the ID (outside of loop) of a page which have a loop of another CPT within its content using a shortcode.
If I do a print_r
of get_queried_object()
, all I get the args used to register the CPT
If I echo
$post->ID
I get the ID of the last item in the secondary loop.
If I echo
get_queried_object_id()
, I get 0
all the time.
Here is the code I am currently using
function get_meta_values() {
global $post;
$queried_object = get_queried_object();
echo '<pre>';
print_r( $queried_object ); //Returns args used to register the CPT
echo '<br> $queried_object->ID: ' . $queried_object->ID; //Returns Nothing
echo '<br>get_queried_object_id(): '. get_queried_object_id(); // Returns 0 all the time
echo.'<br>PageID: ' . $post->ID; // Returns the ID of last item in the secondary loop
echo '</pre>';
}
add_action( 'wp_footer', 'get_meta_values' );
My goal is to get the ID of the page (where the shortcode is) to retrive some custom field values.
EDIT: I am using WooCommerce, but the shortcode that outputs the products is custom. I know I could bypass the issue by other means, but just curious why this is not working.