Title: Sorting Posts ASC and DESC Same Link
Last modified: August 30, 2016

---

# Sorting Posts ASC and DESC Same Link

 *  [VNConsort](https://wordpress.org/support/users/vnconsort/)
 * (@vnconsort)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/sorting-posts-asc-and-desc-same-link/)
 * Hi there. Currently I have a table where I can order titles asc and desc but 
   with individual links such as “A-Z” and “Z-A”.
 * I would like it if there was just a link called “Titles” and when the user clicks
   it, it’ll sort by ASC and then once clicked again it’ll sort by DESC.
 * The following is my code for what I currently have but I am not sure how to approach
   this to combine in one link.
 *     ```
       <?php
           $type = 'shows';
           $args=array(
             'post_type' => $type,
             'post_status' => 'publish',
             'posts_per_page' => -1,
             'ignore_sticky_posts'=> 1
           );
   
           if( isset( $_GET['sort'] ) && "titleasc" == $_GET['sort'] ){
               $args['orderby'] = 'title';
               $args['order'] = 'ASC';
           }
   
           if( isset( $_GET['sort'] ) && "titledesc" == $_GET['sort'] ){
               $args['orderby'] = 'title';
               $args['order'] = 'DESC';
           }
       ```
   
 * The link I currently have is:
    `<th>Title <span><a href="?sort=titleasc">A-Z</
   a> <a href="?sort=titledesc">Z-A</a></span> </th>`
 * Your help is greatly appreciated. Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [VNConsort](https://wordpress.org/support/users/vnconsort/)
 * (@vnconsort)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/sorting-posts-asc-and-desc-same-link/#post-6840707)
 * Still searching for an answer if anyone wants to take a stab.

Viewing 1 replies (of 1 total)

The topic ‘Sorting Posts ASC and DESC Same Link’ is closed to new replies.

## Tags

 * [orderby](https://wordpress.org/support/topic-tag/orderby/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [VNConsort](https://wordpress.org/support/users/vnconsort/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/sorting-posts-asc-and-desc-same-link/#post-6840707)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
