-
vburdyko
Hi there,
Current Query Loop work:
Currently, when the Tanoxomies/Tags option is selected in the Select Query Parameter field, and for example, two tags are selected in the Tags field, the loop displays posts that have either the first or the second tag (it works with an OR condition). But I want it to show only posts that have both tags added. In other words, I want the condition to work with an AND logic. Unfortunately, I don’t see such settings in the query loop itself. Is it possible to achieve this with additional PHP code?Thank you.
-
Hi there,
Try this:
1. Add an CSS class to the Grid block of the query loop, eg. my-css-class.
Adding CSS class(es): https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/2. Add this PHP code to set up the AND logic:
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-css-class' ) !== false ) { $query_args['tax_query'][0]['operator'] = 'AND'; } return $query_args; }, 10, 2 );
Adding PHP: https://docs.generatepress.com/article/adding-php/
-
vburdyko
Perfect! Thanks.
-
No Problem 🙂
- You must be logged in to reply to this topic.