Custom Post Types and Taxonomies

WordPress 3.0 introduced custom post types and taxonomies. Well apparently the taxonomies have been around for some time.

Six Revisions has excellent tutorials for custom post types and custom taxonomies. Justin Tadlock has some excellent write-ups too. These explain the code needed in functions.php to create custom post types, taxonomies, and how to register those taxonomies to the post types.

Everything is done with the register_post_type() and register_taxonomy() functions. The details of the parameters they take can be found in the function reference.

It might be necessary to include 'rewrite'=>array('with_front'=>false) as one of the arguments when registering the post type so as to solve the 404 errors.

For my site’s purposes, I created a custom post type called Sermons, and a custom taxonomy called Speakers, which will be assigned to the Sermon post type. This will create a top level link in the admin interface to add new sermons, and the entries in the Speakers taxonomy can be managed there too. The alternative would have been to use categories in a normal post to indicate that it’s a Sermon, and to create dummy users as authors for the Speakers.

The custom method not only provides a more intuitive interface for adding the content type, it also allows all sermons by a certain speaker to be retrieved, without have to add dummy users for them. To me, this makes more sense.

Note that for the taxonomy, the ‘hierarchical’ flag indicates whether it will behave like a Category or a Tag. I set the flag to true as I do not want multiple spellings of the same speaker showing up.

Advertisements

One thought on “Custom Post Types and Taxonomies”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s