Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a post type that includes a taxonomy for (1) location and (2) a day of the week.

I'm using the first taxonomy to sort the posts into groups. Here's the loop I'm using:

<?php 
$terms = get_terms('cell-locations');
$argv = array(
                'orderby'       =>  'by_term',
                'hide_empty'    => false
                );
foreach ($terms as $term) {
  $wpq = array ('taxonomy'=>'cell-locations','term'=>$term->slug);
  $myquery = new WP_Query ($wpq);
  $article_count = $myquery->post_count;
  echo '<div class="accordionButton">';
  echo "<h2 class=\"cellHeader\" id=\"".$term->slug."\">";
  echo $term->name;
  echo "</h2>";
  echo '</div>';
  echo '<div class="accordionContent">';
  if ($article_count) {
     echo "<ul class='cell_list'>";
     while ($myquery->have_posts()) : $myquery->the_post();?>
                            <li class="cell-item">
                                <ul class="cell-list">
                                    <li><?php $terms_as_text = get_the_term_list( $post->ID, 'cell-days', '', ', ', '' ) ;
                                        echo strip_tags($terms_as_text);
                                    ?> </li>
                                    <li> <? echo get_post_meta(get_the_ID(), '_cell_leader', true); ?> / <?php echo get_post_meta(get_the_ID(), '_cell_apprentice', true)?></li>
                                    <li>Get in touch with <a href="mailto:<?php echo get_post_meta(get_the_ID(), '_cell_leader_email', true);?>"><?php echo get_post_meta(get_the_ID(), '_cell_leader', true);?></a></li>
                                </ul>
                            </li>

     <?php endwhile;
     echo "</ul>";
  }
  echo '</div>';
}
?>

This gives me a nice accordion-style layout based on the taxonomy term, "cells-location." This works all fine, except I now want to sort the posts within each location according to the other taxonomy, "cells-days." I've used a plugin to give them a sort order (http://wordpress.org/extend/plugins/taxonomy-terms-order/). The api for the plugin offers the following query arguments to call the posts in order:

 $argv = array(
                'orderby'       =>  'term_order',
                'hide_empty'    => false
                );
get_terms('category', $argv);

I'm having trouble creating this second loop within the first loop. Any thoughts or suggestions?

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.