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.
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.
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.
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.
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_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...