Combine parameters in the query loops

Hey there,

I have a category page where I want to display new pages from that category combined with another category. If I add taxonomies it shows the pages from both the categories. So it’s either getting pages from category A or from pages with category B. Now I want to combine them. So only show pages who have Category A and B.

How can I do this in the query loops functions?

Thank you.

Hi @ogc2022,

To clarify, are you wanting to query posts who have BOTH category A and B in your GB Query Loop Block?

Yes. I want them to have category A and B. Not A or B.

I see. If that’s the case, give the Grid Block of the Query Loop Block this class: cu-query-loop.

Then, add this snippet:

add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
		if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'cu-query-loop' ) !== false ) {
			$query_args['category__and'] = array(29, 372);

		return $query_args;
	}, 10, 2 );

Replace 29 and 372 with the category IDs of your preference.

Adding PHP: Adding PHP - Documentation

Thank you @fernandoazarcon2

I will give it a try.

It’s working. Except for the pagination. It’s broken with the above code.

Can you share the link where you placed this Query Loop?

May we also know how it was broken specifically?

Hello @fernandoazarcon2 thanks for your reply. It didn’t work for me so I changed the page into something else. I thank you for your replies! This thread can be closed.

I see. You’re welcome!