-
honzapecenka
In Generateblocks v1, I have a query loop. On the grid located below the query, I have set the CSS class My-order, which sorts the posts in the list according to the ACF field Datum. The code is as follows:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { // apply filter if loop has class: my-order if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-order' ) !== false ) { $query_args['orderby'] = 'meta_value'; $query_args['meta_key'] = 'datum'; $query_args['order'] = 'ASC'; } return $query_args; }, 10, 2 );In GB v2, when I put the My-order class on Looper, this code does not work and I cannot target it correctly to make it work. Can you help, please?
-
Hi there,
1. Add the
my-orderclass to the query block in v2.2. and change
generateblocks_query_loop_argstogenerateblocks_query_wp_query_args.Let me know if this helps!
-
honzapecenka
The change didn’t help.
https://prnt.sc/HtoM-Qd_rJp-
https://prnt.sc/2w-XYWkkVaZv -
You are using the Inherit query from template option, so the order will be inherited from the default template. This code cannot change its order.
-
honzapecenka
In GB v1, it worked as inherited from the template. When I turn it off, it works.
-
honzapecenka
I tried this code and it works with the settings inherited from the template.
add_action( 'pre_get_posts', function( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } // jen archiv a pozvánky if ( ! is_category( [ ID, ID2 ] ) ) { return; } $query->set( 'orderby', 'meta_value' ); $query->set( 'meta_key', 'datum' ); $query->set( 'order', 'ASC' ); }); -
Yes, that’s a better approach to adjust the order for the posts themselves, instead of adjusting the order at the query block level.
-
honzapecenka
Thank you for help 🙂
-
You are welcome 🙂
- You must be logged in to reply to this topic.