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.

Simply put, is it possible to sort a taxonomy.php template via the same methods you can with something like wp_query so that the archive shows all posts in an ascending order alphabetically by title?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

you can query_posts and orderby=title:

<?php //*The Query*//
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
query_posts($query_string . '&post_type=YOUR-POST-TYPE&posts_per_page=1&orderby=title&order=asc&paged='.$paged);
if(have_posts()) : while(have_posts()) : the_post();
?>

<?php endwhile; ?>

<?php else : ?>

<?php endif; wp_reset_query(); ?>

more info: WP_Query#Order/Orderby Parameters

share|improve this answer
    
I guess theres no danger in using query_posts then correct? Im just always weary of using it versus wp_query since it seems to potentially cause more additional issues with paging, or effecting other loops on the same page, etc. –  Mr.Brown Dec 19 '11 at 16:06
    
Yes @Mr.Brown , you will not have a problem if you reset your query, if you have any conflicts with other queries, build a custom query and include the "orderby" and "order" parameters –  Philip Dec 19 '11 at 18:50
    
Ok thank you, Ill give this a try and report back. –  Mr.Brown Dec 19 '11 at 22:48
    
Ok this works for sorting the posts as I wanted but now Im loosing paging as a result. How might I construct a custom query similar to the one your referring to as an alternative? Thanks. –  Mr.Brown Dec 19 '11 at 22:57
    
Apologies, what I meant to say is that when using posts_per_page paging seems to not work correctly...but when using the Reading Settings instead of posts_per_page I seem to get the correct results. –  Mr.Brown Dec 19 '11 at 23:31
show 5 more comments

Your Answer

 
discard

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

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