Sort Post by Category in Alphabetical Order
-
I’m having trouble sorting post based on a custom category. I can sort all post alphbetically, but I want to sort post alphabetically based on the category they are affliated with.
I have created five categories, AE, FJ, KO, PT, & UZ
Basically I have a drop down, and want the user be able to select the category and be displayed alphabetically.
<div id="sort"> <label>Sort by</label> <form action="<?php bloginfo('url'); ?>/grants/all-grantees" method="get"> <select name='sort' onchange='return this.form.submit()'>"> <option>Please Choose</option> <option value="D">Most Recent</option> <option value="A">Name (Ascending)</option> <option value="Z">Name (Descending)</option> <option value="AE">A-E</option> <option value="FJ">F-J</option> <option value="KO">K-O</option> <option value="UZ">U-Z</option> </select> </form> <div class="clear"></div> </div> <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $sort = $_GET['sort']; if ($sort==A) { // sort A-Z $wp_query->query('post_type=grants'.'&orderby=title'.'&order=ASC'.'&paged='.$paged); } elseif ($sort==Z) { // sort Z-A $wp_query->query('post_type=grants'.'&orderby=title'.'&order=DESC'.'&paged='.$paged); } elseif ($sort==D) { // sort chronological (Latest post to the Oldest Post) $wp_query->query('post_type=grants'.'&orderby=date'.'&order=DESC'.'&paged='.$paged); } elseif ($sort==FJ) { // sort alphabetical (A - E) $wp_query->query('post_type=grants'.'&orderby=title'.'&order=ASC'.'&paged='.$paged); } else { //sort chronograntslogical (Latest post to the Oldest Post) $wp_query->query('post_type=grants'.'&orderby=date'.'&order=DESC'.'&paged='.$paged); } ?> <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Sort Post by Category in Alphabetical Order’ is closed to new replies.