I have woocommerce page for my products that is treated like an archive page. I need to get the ID for the archive page but obviously if I use $post->ID or get_the_id(), etc. I get the id for the most recent post on that page.

2 Answers
2

If this is a true page, then you can get the ID of that specific page with get_queried_object_id(). This works and will return the ID on the specific pages, single, category, taxonomy, tag and author pages where it is used. True date and time archives and the homepage will not have ID’s

You can do the following

$page_id = get_queried_object_id();
echo $page_id;

Just one very important note, query_posts breaks the main query which breaks the functionality above. This will lead to incorrect data. So make sure that you never ever use query_posts

Leave a Reply

Your email address will not be published. Required fields are marked *