-
chrismai
Hi GP,
I’m using GP and GB pro to create a large site and it’s been really great so far, I’m just getting a bit stuck when it comes to the search results page and using multiple query loops.
The design calls for search results to be split over different tabs i.e
Pages(5) | Posts(3) | Products(6)Currently, I have achieved this by using 3 Query Loops set to “Inherit query from template” and then using display “none” on the various tabs, but this feels much heavier than it perhaps should be.
Is there a way to use multiple Query Loop blocks that pull in the search term but are then filtered to different content types (page, post, product) before being output?
Many thanks
Chris -
Hi there,
not sure on this…. but you can try:
1. Your Loop Template.
add the 3 query loops each set toInherit Query from Template
2. each Query Loop Block, select the Grid Block and in Advanced > Additional CSS Classes add the respective CSS Class:
posts-query
pages-query
products-query
3. Add this PHP Snippet to filter the
generateblocks_query_loop_args
add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'posts-query' ) !== false ) { // merge meta_key $custom_term slug into tax query return array_merge( $query_args, array( 'post_type' => 'post' ) ); } if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'pages-query' ) !== false ) { // merge meta_key $custom_term slug into tax query return array_merge( $query_args, array( 'post_type' => 'page' ) ); } if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'products-query' ) !== false ) { // merge meta_key $custom_term slug into tax query return array_merge( $query_args, array( 'post_type' => 'product' ) ); } return $query_args; }, 10, 2 );
That function should set the the queries post-type to
post
,page
, orproduct
for each loop based on the CSS class it was given.But its a punt i am not sure it will work in this instance.
-
chrismai
Ha, for a punt that was a pretty damn good one…
Works exactly as expected, and even returns better results than my initial method, thank you David 🙂
-
Well, look at me lol – having one of those days 🙂
Super happy to hear that!!
- You must be logged in to reply to this topic.