<?php
add_filter( 'facetwp_facet_where', function( $where_clause, $facet ) {
if ( 'categories_checkbox' == $facet['name'] ) {
$name = $facet['name'];
$tax = str_replace( 'tax/', '', $facet['source'] );
$facets = FWP()->facet->facets;
if ( isset( $facets[ $name ] ) ) {
if ( ! empty( $facets[ $name ]['selected_values'] ) ) {
$term_slug = $facets[ $name ]['selected_values'][0];
$term = get_term_by( 'slug', $term_slug, $tax );
if ( isset( $term->term_id ) ) {
$where_clause .= " AND f.parent_id = '{$term->term_id}'";
}
}
}
}
return $where_clause;
}, 10, 2 );