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)
Viewing 1 replies (of 1 total)
- The topic ‘Sorting Posts ASC and DESC Same Link’ is closed to new replies.