0
votes

I have a custom post type and a taxonomy which allows the user to select which category the post is in.

Here is my custom taxonomy:

add_action( 'init', 'create_talcat_taxonomy', 0);
function create_Talcat_taxonomy()
{
    register_taxonomy ( 'Talcat', 'artist', array( 'hierarchical' =>
    true, 'label' => 'Categories', 'query_var' => true, 'rewrite' => true )
);
}

On my homepage I am querying the post_type=artist , which works fine and brings in my artist posts. However how can I print/display the name of the category that post belongs to and then link to that category page?

2

2 Answers

0
votes

Similar to the_categories WordPress has function the_taxonomies to display custom taxonomies assigned to post type.

http://codex.wordpress.org/Function_Reference/the_taxonomies

Example:

<?php the_taxonomies('before=<ul>&after=</ul>'); ?>

<?php 
    $args = array(
    //default to current post
    'post' => 0,
    'before' => '<p class=\"meta\">',
    //this is the default
    'sep' => ' ',
    'after' => '<p class=\"meta\">',
    //this is the default
    'template' => '%s: %l.'
);
the_taxonomies($args); 
?> 
0
votes

I have managed to find a clean and simple way to achieve printing the taxonomy term assigned to the post with the following:

<?php the_terms( $post->ID, 'TAXONOMY NAME', ' ', ' / ' ); ?>

Using term retrieves the terms associated with the given object(s), in the supplied taxonomies.

Here is a link to the codex with examples and further detail.