Context
- Post Type: Resources
- Taxonomy: Media Type, Term: Audio
- Taxonomy: Series
The following code displays a unique list of the custom taxonomy “Series”
I want to order the list by term_order, but it is not working. Any suggestions?
The site. Currently it’s ordered by ID
<?php
$post_data = array();
$my_query = new WP_Query( array(
'post_type' => 'resource',
'posts_per_page' => -1,
'media_type' => 'audio'
)
);
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
$audio = 16;
// Get all those post_ids for that term
$post_ids = get_objects_in_term( $audio, 'media_type', array('post_status' => 'publish') );
// Then get the series terms for those post ids
$terms = wp_get_object_terms( $post_data, 'series', array('fields' => 'ids', 'orderby' => 'menu_order' ) );
$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>';
}
?>