Why aren’t my posts showing?

This doesn’t work the way you think it does because get_pages doesn’t do what you think it does.

First, understand that all pages, all content, in WordPress is really a “post”. A “Page” is just a special type of post.

Now, in a normal environment, you wouldn’t call “get_” anything. This is why you’re confused, because you’re directly getting things and thus bypassing everything that WordPress does automatically for you. When you call get_pages, then it gets those pages directly. It doesn’t take the “static home page” setting into account, it simply does what it is told and gets the content of those pages.

See, WordPress automatically parses the URL and determines what it is that should be displayed on that URL. This happens according to the rewrite system. The rewrite rules turn a “pretty” URL into a series of parameters for the WP_Query system. The WP_Query system pulls out the posts to be displayed, and saves them in a global $wp_query. The template system then determines which template to pull from the theme based on the various data in that global WP_Query, and then loads that template. The template implements The Loop, which displays the posts contained within the global $wp_query.

So, to sum up:

  • URL gets processed by rewrites
  • Rewrites creates query parameters
  • Query parameters used to determine posts to get
  • Template system examines query to load proper template
  • Proper template displays the posts from the query

Each step here happens all by itself. You don’t really control it, it’s just what WordPress does at start-up.

The “Static Home Page” setting modifies step three there, where the query is getting the “home page” it has a decision to either get the posts from the blog or to get some static page. Similarly, when you tell it to get a specific Page, if that page is set to be the blog, then the query will get the posts to display there instead. Everything else happens normally.

By doing the get_pages yourself, you’re bypassing everything here and just saying to get these pages and display them, period. Nothing else in the system will impact that because you’ve bypassed it all.

If you want to display everything on a single page, then you need to have it get exactly what you want it to display and then display that. In short, “Static Home Page” doesn’t make the Pages have different content, it just changes what content is chosen by the query to display on those particular pages. If you want to get the posts, then you need to call get_posts in some form, or use a custom WP_Query, or modify the main query, or something else. The get_pages() function cannot really retrieve blog posts. Well, it can, but there’s no point since get_posts() does that instead.