Support » Plugin: Query Multiple Taxonomies » Sort Posts

  • Resolved joeleade


    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' );
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    in my theme, which worked OK until I tried filtering using “Tags.”

    I found this post, 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
    		// 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!

  • The topic ‘Sort Posts’ is closed to new replies.