Created
September 12, 2023 15:39
-
-
Save zackpyle/961686d16727b5a51b4295dbc6d13fd9 to your computer and use it in GitHub Desktop.
Custom query for Beaver Builder to combine current taxonomy term archive query + additional separate tax term
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // ignore this line - for gist formatting purposes | |
function fl_builder_loop_query_args_filter( $query_args ) { | |
global $wp_query; | |
if ( 'topic-featured-posts' == $query_args['settings']->id ) { // BB Module ID | |
// Get the current term object | |
$current_term = get_queried_object(); | |
if( $current_term && property_exists( $current_term, 'slug' ) ) { | |
$query_args['tax_query'] = [ | |
'relation' => 'AND', // Make sure all conditions are met | |
[ | |
'taxonomy' => 'topic', | |
'field' => 'slug', | |
'terms' => $current_term->slug, | |
], | |
[ | |
'taxonomy' => 'featured_insights', // additional taxonomy query | |
'field' => 'slug', | |
'terms' => 'featured-topic-page', // taxonomy term to match | |
] | |
]; | |
} | |
} | |
return $query_args; | |
} | |
add_filter( 'fl_builder_loop_query_args', 'fl_builder_loop_query_args_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment