I’m trying to get the ID of my posts archive page.
It’s set via the admin as the posts page so it already has the default Query. The template I’m using is index.php
, Tried using page-blog.php
but since i set that page as the posts archive it used index.php
instead (was kind of thrown off by this).
echo get_the_id()
returns the ID of my top-most blog post (in this case a sticky) instead of the page ID. I am outside the loop.
There’s a similar question here :
ID for posts/blogs page
but the objective is slightly different and the solution there is to instead use get_option('page_for_posts')
to get the posts archive ID, I need a way to detect if I am in the posts archive page.
I tried using :
if (is_page('blog')){ $current_id = get_option('page_for_posts')
but this didn’t work because the global $post
object seems to refer to my sticky post instead of my archive page
Answers i found seems to be workarounds, but doesnt address the underlying problem which is the $post
screwup. Is there something I’m missing or should be doing another way ? I explicitly need my posts archive page to not be my homepage.