1

I can't figure out how to get the original post_id of a specific page if that page has been set as the static posts page of the blog.

I have a page that normally has a post_id of 95, but as soon as I set it to the static posts page, it returns a post_id of 0 and it's causing me lots of headaches.

How can I retrieve the original post_id - which is stored in the DB because it comes right back if I make it not the static posts page any longer.

  • Try global $post, and then $post->id. – Rutwick Gangurde Oct 6 '11 at 7:05
  • Wow, I don't know why I hadn't tried that before. Interestingly, it DOES return me a post_id however it's not the right one! Instead of the expected id of 95, I get id of 336 which is a completely different post. Anyone have any ideas why this is? – JVC Oct 6 '11 at 7:17
2

the id of the posts page is:

$posts_page_id = get_option( 'page_for_posts' );

the conditional tag for the posts page would be: is_home()

edit: the id of the static front page is:

$front_page_id = get_option( 'page_on_front' );
| improve this answer | |
  • Thanks but this isn't at all related to my question. I need to know how to get the original post_id of the home/posts page, not to tell if it IS the home/posts page in the first place. – JVC Oct 6 '11 at 18:15
  • Oops, I stand somewhat corrected as I misunderstood. This DOES return the original post_id of the posts page, which is half the battle! But it does not return the original post_id of the home page. So thank you very much for this, I just need this one last piece... anyone know how to get the original post_id of the home page? – JVC Oct 6 '11 at 19:02
  • afaik, you didn't ask for the static front page id - now edited into my answer. – Michael Oct 6 '11 at 19:10
  • Yep thanks, I had JUST figured this out a few minutes ago. Unfortunately neither is returning anything for some strange reason: if(is_home()){ $postid = get_option( 'page_for_posts' ); }elseif(is_front_page()){ $postid = get_option('page_on_front'); } $postid comes up empty every time. Any idea why? – JVC Oct 6 '11 at 19:11
  • if neither is set in 'settings -> reading' both get_option() return nothing. where exactly have you used the code? – Michael Oct 6 '11 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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