Using custom taxonomy in custom post types means that you can add categories, or tags to your custom posts.
This can be achieved with code like the following – added to your custom post type plugin or via the custom post type definition in your functions.php file:
1 2 3 4 5 6 7 |
register_taxonomy( 'categories', 'portfolio', array( 'hierarchical' => true, 'label' => __('Categories'), 'rewrite' => array('slug' => 'categories') ) ); |
This makes a taxonomy available with the slug “categories” – whereas the standard WordPress loop would use “category”. In this case, it is intentionally different to show that you can name this whatever you want. This means that you could use the following code, if for example you wanted to show all the “websites” in your portfolio custom post type:
1 |
$myposts = get_posts('post_type=portfolio&post_status=publish&numberposts=-1&categories=websites); |
Image Credit: --Tico--
Comment or tweet @douglasradburn