I'm looping through a series of custom post types and then grouping those by a taxonomy term. That is working great, however I have not been able to order these groupings by term_id
.
I used a var_dump to check the term_id
and they are as expected. In fact, no orderby
parameters are working at all - they are always ordered by the taxonomy term title. My taxonomy in this case is issue_area
with terms like 'Human Services', 'Education' and so on.
What am I missing here?
Here is the loop I am using:
<?php
$terms = get_terms('issue_area'); // this is my custom taxonomy
foreach( $terms as $term ):
$termed = preg_replace('/\d/', '', $term->name ); // split out numbers
?>
<h3 class="expert-term"><?php echo $termed; // Print the term name ?></h3>
<?php var_dump($term->term_id); ?> <?php // this returns an int as expected ?>
<ul class="experts">
<?php $posts = get_posts(array(
'post_type' => 'uwmc_experts', // my cpt
'taxonomy' => $term->taxonomy,
'term' => $term->slug,
'orderby' => $term->term_id, // tried: taxonomy_term_id
'order' => 'ASC', // tried DESC - no change
'numberposts' => -1,
));
foreach($posts as $post):
setup_postdata($post);
?>
<?php if( have_rows('experts') ): ?> <?php // acf repeater ?>
<?php while( have_rows('experts') ): the_row();
$image = get_sub_field('expert_photo');
$content = get_sub_field('expert_bio');
$areas = get_sub_field('areas'); ?>
<li class="expert">
<?php // rest of repeater loop stuff here ?>
taxonomy
is valid anymore as a parameter in queries either. Maybe try turning that into atax_query
instead ortaxonomy_slug => term_slug
( though I've had issues with this in the past ) as seen in the linked example. Maybe at that point you'll be able toorderby => 'title'
.