Custom post types can share tags with normal posts. To do this, add the following line into your custom post declaration.
1 |
register_taxonomy_for_object_type('post_tag', 'portfolio'); |
Custom post types can actually also have their own, separate, tags (for each custom post type) making keeping track of all the tags a lot easier. To do this, simply use the following code instead.
1 2 3 4 5 6 7 8 |
register_taxonomy( 'tags', 'portfolio', array( 'hierarchical' => false, 'label' => __('Tags'), 'query_var' => 'tags', 'rewrite' => array('slug' => 'tags' ) ) ); |
This provides a custom meta box in the admin with the label “Tags” and also then uses sets the query var and rewrite to “tags” for this particular tag set. You could also have another custom tag box for this custom post type if you wanted – for example if you were to use the same content in different areas, and wanted to use different tag structures for the same data.
In order to get at this data, you should use the “taxonomy” flag to grab the query_var/rewrite name. So, in this case, you could use something like:
1 |
$tag = wp_tag_cloud("format=flat&link=view&format=array&taxonomy=tags"); |
Image Credit: kevin dooley
Comment or tweet @douglasradburn