I am using the code below to sort by name based on taxonomy and then list the posts within each taxonomy.
First query works ok for alphabetical listing of taxonomies.
The problem i am having is that the posts inside each taxonomy are not listed in alphabetical order. Any ideas?
<ul style="margin: 10px 25px 45px 25px !important;">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
//if (false == ($content = get_transient('os_travel_cache'))){
// ob_start();
$taxonomies = array(
'tax_one' => 'Taxonomy1',
'tax_two' => 'Taxonomy2',
'tax_three' => 'Taxonomy3',
);
foreach($taxonomies as $taxonomy => $title) {
// start div... cor column..
?>
<li>
<div><h6><?php echo $title; ?></h6></div>
<?php
$terms = get_terms( $taxonomy,
array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true ) );
if (!is_wp_error($terms) && is_array($terms) && count($terms) > 0){
foreach($terms as $term){
$args = array(
'post_type' => 'os_book',
'tax_query' => array(
array(
'taxonomy' => $term->taxonomy,
'field' => 'id',
'terms' => $term->term_id
)
)
);
?>
<div class="term_container">
<div class="handler"><span id="ashplus"> + </span><?php echo $term->name; ?></div>
<div>
<ul class="list">
<?php
$rp = new WP_Query( $args );
if ($rp->have_posts())
while ( $rp->have_posts() ) {
$rp->the_post();
$name = get_field('fl_profile_name');
$location = get_post_meta(get_the_id(), 'fl_country', true);
?>
<li data-location="<?php echo $location; ?>"><a href="<?php the_permalink();?>"><?php echo $name; ?></a></li>
<?php
}
?>
</ul>
</div>
</div>
<?php
}
}
?>
</li>
<?php
}
// $content = ob_get_contents();
// ob_end_clean();
// set_transient('os_travel_cache', $content, 1);
// }
// echo $content;
?>
<?php endwhile;
endif; ?>
</ul>