Subscribe!
RSS
  • Moshu
  • Prairie
  • WordPress
  • The combined blog: about WordPress, the Canadian Prairies and myself
    The Journey to full time blogging


How Pages are different in WP 2.1

Pages in versions before WP 2.1

There is a lot of confusion about the Pages in the new WordPress version 2.1. As you may know Pages (with capital P) in WP have a special meaning: those are the quasi-static content webpages where you put your About, Contact us and similar non-post things. I say “quasi” because if you look at them in the database you’ll see they look exactly like the posts, and they are also stored in the wp_posts table… just in the pre-2.1 versions they were flagged with “static” in the post_status field. See Fig. 1.

Old static

In the same time, as you can see, posts (i.e. the entries that are part of the chronological stream) were marked with “publish”. Consequently, many scripts, code snippets, plugins used that flag to select the real posts from the table.
An example for such a code could be a simple query like this:
SELECT ID FROM $wpdb->posts WHERE post_date <'" . current_time('mysql') . "' AND post_status='publish'

In this way the author of the code made sure that only posts are selected from the database - and Pages would be left alone. Since the introduction of the "static" Pages (version 1.5) this code worked well and many plugins and themes with custom query strings are based on this criterion for selection.Empty post_type

The database structure even in those early versions had some fields that were empty; the average user never really cared about them and never even thought why were they in the table or what their purpose was. Such was the case of an empty field toward the right end of the wp_post table called "post_type" (see Fig. 2)

Pages in the new 2.1 version

Well, in WordPress version 2.1 which has been just released yesterday (see my previous post about it) - some major changes happened in how the Pages are handled, marked in the database.

Suddenly all the entries -- be it post or Page -- are flagged as published in the post_status field. What you see in Fig. 3 under posts_status are posts and Pages mixed, and based on this field it is impossible to detect which one is a post and which would be a Page.

new post_status

Obviously, any code (plugin) that uses a code line as illustrated above... will fail, since will query not only the posts but Pages as well. There are already several reports in the WP Forum about plugins for displaying archives list or generate a site map that stopped working. More exactly, they "overwork" - displaying posts and Pages as well.

new post_type

Pages in the new 2.1 WordPress version are defined in the previously empty field: post_type. It's quite simple: they are either "post-type" or "page-type" -- see Fig. 4.

Which, in return, would mean that our code from above must be changed to accomodate this new definition of the Pages:
SELECT ID FROM $wpdb->posts WHERE post_date <'" . current_time('mysql') . "' AND post_type='post'
Notice how we changed only the last portion, replacing post_status='publish' with post_type='post'. I have tested this in a simple Archives plugin and it worked well, the Pages were filtered out and not shown mixed with posts. I was lucky, I had to replace the code only in two lines, so it was easy!

UPDATE. As Kafkaesquí has noted in his comment below, remember that since 'post_status' has no been removed but simply redefined, you may still need to use it in a query! Kaf gave this example:
you may only want to retrieve 'publish'-ed posts, so you'll want something like:
post_status = 'publish' AND post_type = 'post'. [This update is for those that don't read the comments]

Hopefully plugin authors (who have more knowledge about coding than I have) will realize soon the necessity of updating their plugins for the new environment. Of course, if you are brave enough, and you can change a line or two in a plugin... you can give it a try! WARNING! Make a backup copy before your mess around with the code. Also, I wouldn't try it with a plugin that creates its own tables in the database; that might be way more complicated, so better leave it for pros.

Now, after reading it, at least you can bug the plugin authors what to correct in their code ;)

If you find this article useful, click the "Share this" button below and spread the word...


23 Responses

  • Nicholas Shanks ·

    “Correct their code” should probably be just “update their code” since there was never anything wrong, it’s just out of date :-)

  • Waleed Jameel ·

    Hi!

    Thanks for this explanation. Made sense to me.
    Perhaps you can answer a neighboring question of mine. In WP 2.0, each Page could have its own unique template. In WP 2.1, I can’t find that option anymore. You can set a static page for your main_front page and for your blog entries but you can’t define a unique look for the front page? Bogus!

    Any ideas?

    Thanks.

  • Moshu ·

    @Nicholas – Thanks for the correction… & keep in mind that English is my fourth language, so mistakes are prone to happen ;)

    @Waleed – the Page Template option is still there, at least in my install, on the Write Page subpanel where it used to be. So, for defining the “look” of the front page I’d go: create a unique template; create a new Page using that template and put your ‘static’ content in it; select it to be the home page.
    Doesn’t that work for you?

  • Waleed Jameel ·

    Ah! Got it working. There was no page template at all apparently in the theme. Now, as you can see, I’ve simply done a page template for the main page with a launch date.

    Thanks for the pointer Moshu.

  • jez ·

    I came from the wp forums to your page,
    hence you seem to be a genius with sql and php,
    I hope that you might find out what causes this strange behavior with pages and wordpress 2.1 (latest):

    with wordpress 2.1 and the 3.6er sideblog plugin of katesgassis activated,
    pages are hidden and return a 404,

    if I deactivate the plugin,
    they are right back and show.

    any clue?
    faustina of gollygolly.com has the same issue.

    in case you find a quick fix,
    feel free to share it,
    cheerio!

  • Moshu ·

    Hey, jez, I could never write one line of PHP code, not to mention MySQL. (Otherwise, of course, I am a genius, LOL)
    Let’s say I am just an advanced WP user.

    As for your question: I guess you gave yourself the answer. The plugin interferes with the normal flow of the Pages. Only the plugin author would be able to fix it.

    Simply: that plugin, or the version you are using, is not compatible with WP 2.1. It has to be updated, as many other plugins.

  • jez ·

    genius, moshu you are,
    that’s why I digged you down man,
    keep the information coming, I hope mr. kate will find a fix :)

  • William ·

    Double up on those thanks Moshu. We need to shake these bugs out of 2.1.

    Jez – I have the same issue but the pages don’t appear when I turn the 3.6er sideblog plugin off.

    Puzzling???

  • Kafkaesquí ·

    Nice post moshu.

    I’d add that since ‘post_status’ has no been removed but simply redefined, you may still need to use it in a query. For example, you may only want to retrieve ‘publish’-ed posts, so you’ll want something like:

    post_status = 'publish' AND post_type = 'post'

  • Moshu ·

    Thanks Kaf, you are absolutely right. I might even update the post for those who don’t read the comments :)

  • Al ·

    Thanks for your clear explanation! Maybe a next WP update will search both postings and pages with their default search. At least, I hope so, since the search everything plugins do fail now with 2.1

  • Patty ·

    I’m a bit confused. I tried to change the “publish” to “post” option in the code, but when I did, none of my posts showed up in the listing, and all of the posts/pages still showed up in the archives.

  • Moshu ·

    Patty, then I am afraid you misunderstood (or didn’t read carefully) what was discussed.

    You do NOT change the “publish” to “post” – those are two different things. See above comment #11 (by Kaf). Where you used to have
    post_status = 'publish'
    now in 2.1 you need this:
    post_status = 'publish' AND post_type = 'post'

    Hope this helps.

  • Patty ·

    Never mind… I got it!! Great, thanks so much!

  • peter ·

    Very enlightening article, but unfortunately my problem stays: after upgrading my pages don’t appear in WordPress (they are saved in the database). The post status is publish and the post type is page in the MySQL so I don’t understand what’s wrong. Hope you guys can help me.

    Cheers.

  • Moshu ·

    peter, the only thing I can think about is: plugins. Try to deactivate your plugins one by one and see if your Pages re-appear or not.

7 Trackbacks/Pingbacks

  1. Playing with WordPress » To upgrade or not to upgrade - to WP 2.1?
  2. [this savage art…] » Blog Archive » Updating Issues
  3. Wordpress 2.1 and the Disappearing Pages
  4. P?ginas y posts en wordpress : Intrucciones de andar por casa
  5. WordPress Wednesday: Easter Eggs, Editor Extras, WordPress Plugins, and more WordPress 2.1 at The Blog Herald
  6. Maurizio Colleluori’s Weblog | Upgrade a Wordpress 2.1.3 e nuovo tema
  7. I dream in colors » Recent posts on Wordpress

RSS feed for comments on this post.   TrackBack URI

Leave a Reply

Do something different
with your WordPress site!

Build SILOS and get in Google's Goodbooks
Here is how to make them LOVING your site:

Silo Manual

GET YOUR FREE REPORT NOW!
(click on the silos!)

Get the free siloing manual
and beat your competition today!




  • Make and save money!
Hassle-free blog setup in minutes   Click here to join Easy Video Producer
RAP Bank   Text Link Ads