[Resolved] Query Loop Sort by Title (ASC vs DESC)

Home Forums Support [Resolved] Query Loop Sort by Title (ASC vs DESC)

Home Forums Support Query Loop Sort by Title (ASC vs DESC)

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2260737
    Ian

    Is there a way to reverse the sort order by Title inside Query Loop?

    #2260738
    Ian

    nvm, as usual, after spending some time without a solution, posting here always result in a solution. Found the “Order” parameter. SOVLED!

    #2260739
    Fernando
    Customer Support

    Glad you found the solution! Feel free to reach out anytime you’ll need assistance with anything else!

    #2260752
    Ian

    Along the line of ordering. When I created a Query Loop, I used “Include Posts and once published, the order was exactly as I had typed them in. In a second Query Loop, the ordering is different than the sequence they are entered. These loops are both on the same page, could this be a conflict?

    #2260757
    Fernando
    Customer Support

    There shouldn’t be a conflict.

    Have you set an “order by” in the parameters? By sequence, are you referring to the sequence they were created?

    Kindly let us know.

    #2260761
    Ian

    By sequence, I meant the sequence that they were inserted into the “Include Posts” parameter. For Order, what order should be set to display the sequence that they were entered?

    #2260774
    Fernando
    Customer Support

    I see. Thank you for clarifying.

    You can’t order the posts through the order in which you add them in Include posts through the Query Loop block settings.

    You’ll need to do it manually through a PHP snippet.

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    		if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query' ) !== false ) {
    			
    			$query_args['post__in'] = array(395672, 394831, 392713);
    			$query_args['orderby'] = 'post__in';
    		}
    
    		return $query_args;
    	}, 10, 2 );

    Add my-query class to the Class list of the Post Template block: https://share.getcloudapp.com/geuR4AQN

    Then replace 395672, 394831 and 392713 with the IDs of your Posts. Add more if needed.

    If you have 2 Query loops, use something like this:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
    		if ( ! empty( $attributes['className'] ) ) {
    			if( strpos( $attributes['className'], 'my-query-1' ) !== false ) {
    				$query_args['post__in'] = array(395672, 394831, 392713);
    				$query_args['orderby'] = 'post__in';
    			} else if ( strpos( $attributes['className'], 'my-query-2' ) !== false ) {
    				$query_args['post__in'] = array(123, 456, 789);
    				$query_args['orderby'] = 'post__in';
    			}
    		}
    
    		return $query_args;
    	}, 10, 2 );

    The first Post template block will have a class of my-query-1 and the other my-query-2

    Hope this helps!

    #2446725
    Mariken de Ruiter

    Hi all,
    Is there a way to reverse the query order? The oldest on top/first, latest post last/bottom?

    #2446923
    David
    Staff
    Customer Support

    Hi there,

    if you’re using a GenerateBlocks Query Loop block then add these parameters:

    Orderby: Post data
    Order: DESC

    #2447156
    Mariken de Ruiter

    Thanks, David,
    Found it. 🙂

    #2447843
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.