-
Bernhard
Hello,
I want to order a query loop by ascending id, so I inserted the taxonomy and selected
order by
id
andorder
ASC
In the editor everything looks fine, but in the frontend I see it ordered by published date ascending. So I’m wondering what is wrong. Can the parametersorder by
andorder
be used together?I cleared the complete site cache, browser cache, but no success.
The query is below the title
https://www.tourist-in-rom.com/en/rome-autumn/#whats-going-on-in-autumn-in-romeThank you
-
David
Hi there,
it “should” work, but it may be a bug. Ill do some tests on a local dev site to see if I can replicate it.
-
Bernhard
Hi David,
I prepared access and excluded the url from cache.
I hope this is useful. -
Alvind
Hi there,
I was able to replicate the issue on my testing site, which seems to be a bug. However, there’s a workaround you can use if you’d like.
Edit the query loop and add the class
order-by-id
to the Grid block under Advanced > Additional CSS Classes.Then, add this snippet:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'order-by-id' ) !== false ) { $query_args['orderby'] = 'ID'; $query_args['order'] = 'ASC'; } return $query_args; }, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/
-
Bernhard
Hi Alvind,
it works, thank you 🙂
The strange thing is that it does not work inserting the snippet as a hook in wp_footer, but it works inserting it in the child theme.
What am I doing wrong? The link to the hook is in the private information. -
Alvind
The snippet is in PHP, so it won’t work if added via hooks like that.
Adding it to the
functions.php
file of your child theme is the correct method. -
Bernhard
OK, thank you 🙂
-
Alvind
You’re welcome 🙂
- You must be logged in to reply to this topic.