- This topic has 10 replies, 4 voices, and was last updated 1 year ago by
David.
-
AuthorPosts
-
June 21, 2022 at 10:13 pm #2260737
Ian
Is there a way to reverse the sort order by Title inside Query Loop?
June 21, 2022 at 10:15 pm #2260738Ian
nvm, as usual, after spending some time without a solution, posting here always result in a solution. Found the “Order” parameter. SOVLED!
June 21, 2022 at 10:16 pm #2260739Fernando Customer Support
Glad you found the solution! Feel free to reach out anytime you’ll need assistance with anything else!
June 21, 2022 at 10:51 pm #2260752Ian
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?
June 21, 2022 at 11:00 pm #2260757Fernando 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.
June 21, 2022 at 11:06 pm #2260761Ian
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?
June 21, 2022 at 11:28 pm #2260774Fernando 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/geuR4AQNThen replace
395672
,394831
and392713
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 othermy-query-2
Hope this helps!
December 2, 2022 at 7:46 am #2446725Mariken de Ruiter
Hi all,
Is there a way to reverse the query order? The oldest on top/first, latest post last/bottom?December 2, 2022 at 8:40 am #2446923David
StaffCustomer SupportHi there,
if you’re using a GenerateBlocks Query Loop block then add these parameters:
Orderby: Post data
Order: DESCDecember 2, 2022 at 11:41 am #2447156Mariken de Ruiter
Thanks, David,
Found it. 🙂December 3, 2022 at 6:19 am #2447843David
StaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.