0

I have a custom post type that has an option to tag that post as part of a 'Topic'. This is set in the taxonomy:

register_taxonomy(
    'topic',
    array('post','blog','shows'),
    array(
        'label' => __('Topics'),
        'hierarchical' => true,
        'public' => true,
        'query_var' => 'topic',
        'rewrite' => array('slug' => 'topic')
        ));
}

And I need a way to get a list of all topics in use by the 'Shows' post type, but I cannot figure out how to do this!

I think it would be something like:

 <?php  $topics = get_query_var( 'topic' );  ?>

but that obviously isn't working. If anyone has suggestions, I would really appreciate it!!!

0

I think I cracked it actually! Used this snippet:

<?php 
  $custom_terms = get_terms('topic');

foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'episodes',
    'tax_query' => array(
        array(
            'taxonomy' => 'topic',
            'field' => 'slug',
            'terms' => $custom_term->slug,
        ),
    ),
 );

 $loop = new WP_Query($args);
 if($loop->have_posts()) {
    echo '<h2>'.$custom_term->name.'</h2>';


 }
}
?>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.