Support » Fixing WordPress » How To List terms for custom taxonomy

  • Problem:
    Best described with an example:

    I want a url structure that is:

    1. (This page links to #2)
    2. (This page displays a list of video topics, the links go to the page #3 but filtered by topic)
    3. (This page displays a list of video titles for the selected topic)
    4. (This page shows the post)

    I created a custom post type – video
    Created a custom taxonomy called video that has terms defining the topics for the videos

    The problem seems to arise in getting the appropriate URLs.

    How do you display the list of topics in the custom taxonomy?
    The most obvious solution would appear to be the use of “wp_list_categories as in the following:

    <h2>Video Subjects</h2>
    <p>Click to see the list of videos under a particular subject</p>
    			<?php $args_list = array(
    'taxonomy' => 'video', // Registered tax name
    			'orderby'            => 'name',
    			'style'              => '',
     			'title_li'           => __(none )
    echo wp_list_categories($args_list);

    The problem is that the URL for each topic link is created as:

    The problem is how do I capture the terms of the custom taxonomy and put them into a url that is of the form

    Another approach I tried, borrowed from a forum post, is

    <?php $terms = get_terms('video');
    echo '<ul>';
    foreach ($terms as $term) {
        echo '<li><a href="'.get_term_link($term->slug, 'video').'">'.$term->name.'</a></li>';
    echo '</ul>';

    But this produces the same url format –

    I also wondered if a “slug rewrite” might give me what I want but it has to be something like library/topic and based on my experiments that appears not to work. So I’m assuming that the slug must be a single set of characters with no additional url elements.

    Any suggestions on how I can create the Url structure I want using custom posts and custom taxonomy.


  • The topic ‘How To List terms for custom taxonomy’ is closed to new replies.