Support » Developing with WordPress » How to display custom taxonomy for CPT

  • Resolved kirasiris

    (@kirasiris)



    So here I am again.

    I’ve been trying to figure out how to display tags(custom taxonomy) for my CPT for each single post that I create in the said CPT.

    So I tried this which is how I wanted them to be displayed:

    
                    <!-- Tags -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h1 class="panel-title"><i class="fa fa-tags" aria-hidden="true"></i> Tags</h1>
                        </div>
                        <div class="panel-body">
                        <?php 
                            $tags_movie = get_the_terms( get_the_ID(), 'tags_movie');
    
                            foreach($tags_movie as $term){
                                echo '<a href="'. $term->slug .'"><span class="label label-success">'. $term->name .'</span></a>';
                            }
    
                        ?>
                        </div>
                    </div>
    

    the problem is that when clicking on them, instead of taking me to the archive.php file it takes me not a 404 error page.

    Maybe this caused by the way in which I have the permalinks set:

    http://localhost/wptests/%postname%/%post_id%/

    Example of actual CPT without clicking at any tag:

    http://localhost/wptests/peliculas/blood-c-the-last-dark/

    Example of actual CPT after clicking any tag:

    http://localhost/wptests/peliculas/blood-c-the-last-dark/accion

    As I said instead of taking me to the archive file, it takes me to 404 error page and the url never changes as it supposed.

    Thanks in advance.

    NOTE in case you neeed them to see them without the pile of code:
    here is how I register the CPT:
    ‘peliculas’

    here is how I registered the taxonomy for the tags for the peliculas CPT:
    ‘tags_movie’

Viewing 1 replies (of 1 total)
  • I solved it.

    
                        <?php 
                        global $post;
                        $terms = wp_get_post_terms($post->ID, 'tags_movie');
                        if ($terms) {
                            $output = array();
                            foreach ($terms as $term) {
                                $output[] = '<a href="' .get_term_link( $term->slug, 'tags_movie') .'">' .$term->name .'</a>';
                            }
                            echo join( ', ', $output );
                        };
                        ?>
    
Viewing 1 replies (of 1 total)
  • The topic ‘How to display custom taxonomy for CPT’ is closed to new replies.