How to sort a list of CPT-onomies
-
I have a two custom post types for Events and Speakers. I’m using CPT-onomies to connect the two and list the Speakers appearing at each event. (So far, so good!)
However, now I need to list the Speakers in a “specific” order – ie: not alphabetical. I have tried using ‘orderby’ to specify a sort order, but the orderby parameter seems to be ignored. I can specify ‘order’ as ASC or DESC, but this only rearranges the alphabetical listing.
Here is the code I am using:
<?php global $cpt_onomy; $args = array('orderby' => 'meta_value_num', 'meta_key' => 'speakerorder', 'order' => 'ASC'); $speaker_terms = wp_get_object_terms($post->ID, 'launch_speakerbio', $args ); if ( $speaker_terms && !is_wp_error( $speaker_terms ) ) { echo '<span class="speakerlist">Speakers: </span>'; foreach ( $speaker_terms as $speaker_term ) { echo '<a class="speakername" href="' . $cpt_onomy->get_term_link( $speaker_term, $speaker_term->slug ) . '">' . $speaker_term->name . ' - '.get_post_meta($speaker_term->term_id, 'speaker_company', TRUE).'</a>, '; } } ?>
And here is a link to the page: https://www.oktane13.com/agenda/
- The topic ‘How to sort a list of CPT-onomies’ is closed to new replies.