Tech, music and video game enthusiast
Adding custom post types to Wordpress 3
In the latest version of the Wordpress blogging platform, the developers have (finally) introduced Custom Post Types, allowing it to become more of a CMS without extensive use of plugins. Unfortunately, after installing the latest version, you’ll probably have noticed that there doesn’t immediatly appear to be any way to create your own. That’s because there is no UI to do this with – doh. The way to do this is to use the recently introducded method register_post_type().
The Example
Lets say you are running a blog that will have podcasts as a content type every so often, but you don’t require a heavyweight plugin like PodPress – Custom Post Types are the perfect solution.
The Code
Take a look at the following code:
register_post_type('podcast', array(
'label' => __('Podcasts'),
'singular_label' => __('Podcast'),
'public' => true,
'show_ui' => true,
'hierarchical' => false,
'query_var' => false,
'supports' => array('title', 'editor', 'author')
));
Whack that straight in your theme’s functions.php file and voila – you’ll see the new Podcast custom post type right there listed underneath the Comments button. So what did this code do exactly?
The Parameters
As you can see, all we’re really doing is calling the new register_post_type() method and sending through some parameters:
- Label is pretty straight forward, what do you want the custom post type to be displayed.
- Singular label is also intuitive, what do you call ONE of your post types.
- Public is a meta argument to determine whether your post type will be accessible via search, menu’s etc… (more about this on wordpress docs)
- Show UI - set to true to show the custom post type on the back end. False can be set to allow extra content to determine how the custom post type is displayed in the back end.
- Hierarchical is a parameter to determine whether each custom post can have or be a parent of another.
- Supports allows you to determine what content creation fields are used when creating or editing a custom post:
- ‘title’
- ‘editor’ (content)
- ‘author’
- ‘thumbnail’ (featured image) (current theme must also support post-thumbnails)
- ‘excerpt’
- ‘trackbacks’
- ‘custom-fields’
- ‘comments’ (also will see comment count balloon on edit screen)
- ‘revisions’ (will store revisions)
- ‘page-attributes’ (template and menu order) (hierarchical must be true)
The Results
Shown below: the new “Podcasts” custom post type. Now start filling that bad boy with some content!
| Print article |

No comments yet.
Incase you missed it – Wordpress 3.0 released!
about 2 months ago - View Comments
Last night Wordpress 3.0 was released to the general public. Having previewed it previously on this blog, nothing has really surprised me in terms of what has been updated – but it is still nice to go from release candidate to full version.
Set up is now quicker than ever, so give it a go on
Wordpress 3.0 – What’s New & How to Prepare
about 3 months ago - View Comments
If, like me, you use wordpress as a daily tool to design, develop and launch websites, you’ll probably be interested in what the creators over at Wordpress are doing with their soon to be released update, version 3.0.
Comments are closed.