Custom post types with custom taxonomies
Category: Wordpress 0Creating a custom post type associated with custom taxonomies. For those who don’t know, a taxonomy is a term (such as category, tag or anything else) related to posts. For more information about taxonomies, you should have a look at WordPress Codex.
In this example, we’ll create a custom post type named Albums, which belong to “Genres” (the custom categories) and have “Performer” as tags. This snippet has to be pasted in your functions.php file. With those 27 lines of codes, you can create a fully functional music albums archive. Ain’t that powerful?
function post_type_albums() {
register_post_type(
'albums',
array('label' => __('Albums'),
'public' => true,
'show_ui' => true,
'supports' => array(
'post-thumbnails',
'excerpts',
'trackbacks',
'comments')
)
);
// Adding the Custom Taxonomy for Genres. Here we can create categories specific for this post type.
register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) );
// Adding the Custom Taxonomy for Performer. Here we can add tags specific for this post type.
register_taxonomy( 'performer', 'albums',
array(
'hierarchical' => false,
'label' => __('Performer'),
'query_var' => 'performer',
'rewrite' => array('slug' => 'performer' )
)
);
}
add_action('init', 'post_type_albums');
If you liked the article share it by Twitter, Facebook and Google +1.








Google Plus Opens first A...
Google has unveiled the first developer application...
Seagate GoFlex – th...
It’s been a little over a year since Seagate...
Baidu to have a new mobil...
Baidu, the biggest search engine from China, ,...
How to Download YouTube S...
YouTube is a video-sharing website, created by three...
How to Download YouTube S...
Youtube is the largest site with movies and clips....