-1

I have a problem with get_pages. It displays the wrong ID for the blog page. I have tried this code.

$pages = get_pages(array("echo" => 0));
foreach($pages as $page){
    echo $page->ID;
}

But for the blog page it returns the wrong ID. It should be 1 (the blog page is automatically 1 if I understand it correctly) but instead it returns the ID of the actual page.

I've also tried the is_page() function, but that doesn't seem to work on objects.

Is there any way arround this issue?

1

No, the blog page is just a regular page, it has no special ID number and it can be anything. The only special thing about a blog page is that it was assigned to use as a "blog" page and you can check for its ID value in one of the options.

  • Ah wow. wp_reset_postdata was commented. That's why it reported 1 (which is ofcourse the hello world post, doh). – Jeroen Jan 7 '16 at 10:21
  • can be anything is ambiguous and wrong – Pieter Goosen Jan 7 '16 at 10:30
  • @PieterGoosen, suggestions on how to make it clearer are welcome. As for the wrong part, I don't get it. – Mark Kaplun Jan 7 '16 at 10:41
  • The blog page ID is not anything, it is the ID of the page that was assigned as blog page as I have stated in my answer;-) – Pieter Goosen Jan 7 '16 at 10:47
  • @PieterGoosen, I think you get it backwards ;) first there is a page that can have any ID number and only then it is assigned into the option that include the value of the ID of the blog page :) – Mark Kaplun Jan 7 '16 at 11:59
1

The ID of the blog page will be the ID of the page that you assigned as the blog page. This can be very easily be checked by adding the following code in your header

var_dump( get_queried_object() )

That will dump the entire page object of the page that was used as the blog page. The whole static front page and blog page thing is quite confusing here. Although you created a page in backend and assigned a template to it, once you set that page as a blog page, either home.php or index.php is used to display the blog page and not the template set when you created that page.

As to why you are thinking the ID should be 1, I don't know. Would be nice if you can link to some resources

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.