Support » Fixing WordPress » Display Custom Post Type with Custom Taxonomies

  • Anyone have any idea how to display a list of custom taxonomies registered under a custom post type on the post type archive page?

    Or, how to display the custom taxonomy on the custom post type’s single page?

    I’d also like to append the custom taxonomy tags as a div class to each post.

    You can see what’s going on here:

Viewing 8 replies - 1 through 8 (of 8 total)
  • David


    are you just wanting to list the tags associated with that post?

    Well, I guess it’s three things, really.

    1. List all custom taxonomies as text on the custom post type archive page.

    2. List a post’s associated custom taxonomy terms on a custom post single page.

    3. Add a class of the custom taxonomy to the post div class, and add custom taxonomy text to links.


    To elaborate, I want a list of custom categories at the top of the custom post archive page. But I want to customize their link text because I want to use this jQuery sorting plugin.

    So ideally, the <a href> for each listed category would be a hash tag (#) followed by the taxonomy term, like this:

    <li><a href="#custom-taxonomy-name-one">Custom Taxonomy Name One</a></li>
    <li><a href="#custom-taxonomy-name-two">Custom Taxonomy Name Two</a></li>

    THEN, each post would have the taxonomy term as a class, like this:

    <article class="custom-taxonomy-name-one">
    <article class="custom-taxonomy-name-two">

    Does this make sense?

    I’m going to put this here because this is terribly documented, practically un-Googleable. I found a partial solution to adding the custom taxonomy tags to the post classes:

    <?php add_filter( 'post_class', 'mysite_post_class', 10, 3 );
    if( !function_exists( 'mysite_post_class' ) ) {
         * Append taxonomy terms to post class.
         * @since 2010-07-10
        function mysite_post_class( $classes, $class, $ID ) {
            $taxonomy = 'you_custom_taxonomy_term';
            $terms = get_the_terms( (int) $ID, $taxonomy );
            if( !empty( $terms ) ) {
                foreach( (array) $terms as $order => $term ) {
                    if( !in_array( $term->slug, $classes ) ) {
                        $classes[] = $term->slug;
            return $classes;

    Just add it before the post tags after the loop starts.

    More documentation here:



    I tried googling a solution as well, no luck im afraid. If you don’t find a solution here maybe try posting this question in the advanced section.

    How does one gain access to the wp-advanced forum? It says you have to be a moderator to post there.



    I just had a read and they say to add the modlook tag to your post, hopefully they’ll come along and have a look, soryr I couldn’t help, good luck

    Thanks, David!

    Thanks a ton @mrangelmarino – your code worked perfectly for what I wanted to do!

    I just pasted it into functions.php, added the name of my custom taxonomy and bingo, now when I use post_class() I get the tax terms too!


Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display Custom Post Type with Custom Taxonomies’ is closed to new replies.