WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Basically, after setting up the initial "page for post" on the Reading Options, and then add that page to the menu I get the posts when I click on that menu item as expected.

On there I know the post ID (which is the actual page created before setting it as the page for posts) and all the information regarding that same page.

Trouble is, when I click on a specific post, not only the menu item looses its active status, but I can't get hold of that parent page ID.

Is there a way to get that parent page ID, when on a post !?

Edit: For reference, I managed to get it with get_option('page_for_posts'); but that's very ugly. Is not possible that the post associates with it's parent page index ?

share|improve this question

I believe you want get_queried_object. If you have set your static front page and blog page from wp-admin->Settings->Reading then get_queried_object will give you information about the page you chose rather than about the posts in the Loop.

Be aware that get_queried_object will return very different types of information depending on the kind of page you are on. From the Codex:

On your posts page it should be a WP_Post object

$thispage = get_queried_object();
var_dump($thispage); // WP_Post object
share|improve this answer

How about global $post before the loop?

share|improve this answer
Even with that. $post->parent comes empty. I managed to manually get it with get_option('page_for_posts'); but that's not elegant at all – Edu Mar 29 '12 at 7:39
You're only setting that page as the posts page right? But that page not necessarily is a child of some other page. I think you need to use the ID of the global $post variable, and before the_loop begins. – Rutwick Gangurde Mar 29 '12 at 7:47
Yes i've set it as the post page indeed. Should that page not be parent of any posts assigned to it ? What do you mean, use the ID of the global $post variable ? I tried it, and parent is empty. – Edu Mar 29 '12 at 7:54
Why do you need the parent? You just that post page's info right ? That page doesn't become the posts parent! – Rutwick Gangurde Mar 29 '12 at 8:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.