beaverbuilder / feature-requests

Feature request board for Beaver Builder products.
26 stars 4 forks source link

Exclude child terms from BB Post module Taxonomy filter (hierarchical) #370

Open studioavanti opened 2 weeks ago

studioavanti commented 2 weeks ago

Can you please consider adding an option in the Post module Taxonomy filter to Exclude or Include child terms when using a hierarchical Taxonomy?

Details

With a hierarchical Taxonomy having, for instance, test as a parent term and test child as its child term. When applying a Taxonomy filter to a BB Post module with the parent term selected (Match these categories…: test), the grid displays posts having the parent term OR the child term (only).

In other words, despite the child term is not set in Match these categories…, the filter still includes posts having only the child term and not the parent term assigned

A custom PHP filter below is required to exclude posts having only the test child term:

add_filter( 'fl_builder_loop_query_args', 'av_filter_by_term' );
function av_filter_by_term( $query_args ) {

    if ( 'av-filter-by-term' == $query_args['settings']->class ) {

        $query_args = array(
            'post_type' => 'post',
            'tax_query' => array(
                array(
                    'taxonomy' => 'category',
                    'field'    => 'slug',
                    'terms'    => 'test',
                    'include_children' => false
                )
            ),                          
        );

    }

    return $query_args;

}