Custom Post Types in WordPress 2.9
WordPress 2.9 isn’t quite out yet, although it looks like it might make it before the end of the year. Even so, many of us are playing with the betas and seeing what the new features can do. One of the features that usually gets a mention but little else is custom post types.
Post types are not new in 2.9. The post table in WordPress has had a post_type field since 2.0 which was released way back in 2005. Posts and pages are the same thing internally, but have a different value in the post_type field. This affects how they are treated by loop queries, so you don’t get pages on your archive and category pages, etc. In addition the post_type field can mark an object as a revision or an attachment.
So, today there are only four recognized values for post_type: post, page, revision, and attachment. There is no reason you couldn’t use other values, and some plugins may, but the core WordPress code will ignore those entries.
In 2.9, you can add new post types. So, why would you want new types? The main reason I can think of is to give you more formatting power for structured content. Take book reviews for example. They have certain standard elements: the title, the author, the reviewer’s name, and the text of the review. If you make a separate type for book reviews, you could put the author and title in custom fields and format those posts in a special way. All sorts of things have specific elements like this. Look at the plugin directory on WordPress.org. Look at font directories. Recipes, products for sale, auctions, job listings. They all have specific parts that could be pulled out into custom fields and then formatted according to your theme. Then, if you want to change the way you format a custom type of post, you can just change the theme. With the different parts in different fields, you have much more flexibility in formatting.
Sounds great, right? Yes, but we’re not there yet. In 2.9, all you get to do it register a new type as being searchable or not. In addition, you can only do that in plugins (or in a functions.php file in your theme, I suppose). You still have to put your special fields into WordPress’s regular custom fields and retrieve them the same way in your theme files. There is no provision for specifying, for example, that a concert consists of a label of some sort, a location, a date, a time, and a list of artists. If you could, we could image WordPress giving us those fields right along with title and text on the post edit page. And we could imagine getting some formatting functions for our themes, so we could write <?php echo the_concert_date(); ?> instead of <?php get_post_custom_values('concert_date', $page->ID) ?>. Not hugely important, but nicer to read and maintain. All of this is just syntactic and UI sugar, but it is important if we want WordPress to continue growing as a CMS.
So, the upshot is that plugins can now define custom post types, but they have to do all the heavy lifting if they want to make those types easy to use. That said, we can see a much brighter future and 2.9 is showing us the way.



[...] Continue reading here: Custom Post Types in WordPress 2.9 @ Templature [...]
[...] Custom Post Types in WordPress 2.9 [...]
[...] Custom Post Types in WordPress 2.9 @ Templature. [...]
[...] 3.0 di WP introdurrà un supporto migliore ai tipi di post personalizzati. Per approfondire: Custom Post Types in WordPress 2.9 e Custom Post Types [...]