Output Beaver Builder CPT Posts in a Module that belong to a Custom Taxonomy

Using Beaver Builder loop modules to output posts can be limited when you want to output a CPT that belongs to multiple custom Taxonomies but you only want posts to display from one taxonomy – this can be achieved in code using the fl_builder_loop_query_args filter.

<?php
add_filter( 'fl_builder_loop_query_args', 'prefix_fl_builder_loop_query_args_filter' );
/**
* Filter Beaver Builder Loop in Modules - to output a certain Taxonomy
* @since 1.0.0
*/
function prefix_fl_builder_loop_query_args_filter( $query_args ) {
if ( 'id-goes-here' == $query_args['settings']->id ) { // Set an ID in module
$query_args = array(
'tax_query' => array(
array (
'taxonomy' => 'taxonomy-goes-here', // Add in Taxonomy
'operator' => 'EXISTS', // This operator ensures all relevant terms are output
)
),
);
}
return $query_args;
}
view raw loop.php hosted with ❤ by GitHub

In the above code snippet – you need to ensure the BB Module has an ID set in the Advanced tab of the module and also in the filter above – then the taxonomy that you want is added in the tax_query array (or array of arrays) as the value for taxonomy.

It is also assumed that the actual CPT is chosen in the actual BB Module.

Now only posts from that chosen Taxonomy will be displayed.

Leave a Comment