0

I have a custom post type of Clients. The "Client Categories (taxonomy terms)" are called via taxonomy-client.php. I'm able to get the results to output as expected but I can't figure out how to get them to order by title. Here is the code I'm using:

<?php $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); ?>    
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?> 
<h2><?php the_title();?></h2>
<div class="content"><?php the_content(); ?></div>
<?php endwhile; ?><?php endif; ?> 

Thanks in advance

1
  • Guess no one has an answer? :( I can't be the only one w/the issue. Commented Nov 14, 2013 at 16:21

1 Answer 1

1

After about 100 different tries, I got it to work. Not sure if there is a better way, but it works.

$term_slug = get_query_var( 'term' );
    $taxonomyName = get_query_var( 'taxonomy' );
    $current_term = get_term_by( 'slug', $term_slug, $taxonomyName );
    $args = array(
    'post_type' => 'clients',
    'posts_per_page' => -1,
    'orderby' => 'title',
    'order' => 'ASC',
    'tax_query'=>array(
            array(
            'taxonomy'=>$taxonomyName,
            'field'=>$term_slug,
            'terms'=> $current_term,
            )
        )
    );
<?php $query = new WP_Query($args); while ($query->have_posts()) : $query->the_post();?>
//stuff here
<?php endwhile; ?><?php wp_reset_query(); ?>    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.