Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackpyle/961686d16727b5a51b4295dbc6d13fd9 to your computer and use it in GitHub Desktop.
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
<?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