WordPress.org

Ready to get started?Download WordPress

Forums

List Terms Within Another Term (1 post)

  1. izharbuen
    Member
    Posted 1 year ago #

    I have two custom taxonomies called "Series" and "Media Type."

    Media Type has two terms: "Audio" and "Video"

    I want to list all the "Series" terms that are inside "Audio" term.
    (http://eaglesonline.org/resources/videos/)

    I used the following code to list the "Series" within "Video" and it worked. But when I use it to display "Series" within "Audio" only 2 out of the 5 "Series" appear.

    (As of now, there are 24 audio series and 5 video series. Would it be too much to query?)

    Why is it working for the video series but not the audio series?

    <?php
    get_template_part( 'loop', 'page' );
    query_posts( 'post_type=resource&media_type=video');
    ?>
    
    <h3>Listen To/Download Video Series</h3>
    
    <div id="resources">
    <ul id="itemContainer">
    
    	<?php
    
    		$post_data = array();
    
    		$my_query = new WP_Query( 'post_type=resource&media_type=video' );
    		if ( $my_query->have_posts() ) {
    			while ( $my_query->have_posts() ) {
    				$my_query->the_post();
    					$post_data[] = get_the_ID();
    			    }
    			}
    
    			// Start with whatever ID you want to have from Media Type
    			$video = 17;
    
    			// Get all those post_ids for that term
    			$post_ids = get_objects_in_term( $video, 'media_type', array('post_status' => 'publish') );
    
    			// The get then the series terms for those post ids
    			$terms = wp_get_object_terms( $post_data, 'series', array('fields' => 'ids', 'orderby' => 'custom_sort' ) );
    			$result = array_values( array_unique($terms) );
    
    			?>
    
    		<?php
    	$a = $result;
    
    	foreach ($a as $v) {
    	$term = get_term( $v, 'series');
    	$name = $term->name;
    	$slug = $term->slug;
    	echo '<div class="resource-item"><a href="'.get_term_link($slug, 'series').'" title="'.$name.'"><div class="play"></div><li>'.$name.'</li></a></div>';
    	} 
    
    	?>
    
    </ul>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic