Sorting posts on taxonomy page alphabetically like an index
<?php global $wp_query; query_posts( array_merge( array( 'order' => 'ASC', 'orderby'=>'title', 'posts_per_page' => 20, ), $wp_query->query ) ); ?>
I’m putting this here because it gave me so much grief to figure out that I’m sure there has to be some other noob looking to do the same thing. Plus I’ll be able to find it again next time I need it.
I have a newspaper website, with a category ‘Obituaries’, and custom taxonomy “obit year” (because obits are not always submitted in a timely manner, I can’t make use of the post-date)
I made a category-obituaries template so when someone views Obituaries they see the 5 most recent postings and made a list in the sidebar of the taxonomy terms (ie. 2010, 2009, 2008) using a wp_list_categories($args).
Clicking those terms brings you to the taxonomy-obityear.php template where I needed to sort alphabetically. The above code goes in that template just after the “if have_posts()”
The key was in the Codex under “Preserving the Original Query. I read so many posts on how to query without any mention of this. I couldn’t figure out how to keep the original loop but customize the presentation.
It’s so simple….once you know the answer 😉
- The topic ‘Sorting posts on taxonomy page alphabetically like an index’ is closed to new replies.