Sort Posts
-
Hi All,
I had an issue sorting posts using QMT with checkboxes, and filtering by “Tags”.
I first tried adding
query_posts( $query_string . '&orderby=title' . '&order=ASC' );
before
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
in my theme, which worked OK until I tried filtering using “Tags.”I found this post https://bit.ly/116bwHO, from which I grabbed the below code:
// Runs before the posts are fetched add_filter( 'pre_get_posts' , 'my_change_order' ); // Function accepting current query function my_change_order( $query ) { // Check if the query is for an archive if($query->is_archive) // Query was for archive, then set order $query->set( 'orderby' , 'title' ); $query->set( 'order' , 'asc' ); // Return the query (else there's no more query, oops!) return $query; }
Works a treat!
https://www.ads-software.com/extend/plugins/query-multiple-taxonomies/
- The topic ‘Sort Posts’ is closed to new replies.