'FacetWP and ACF relationship (true/false field)

I have 2 custom post types. company and employees. Can select a company from employees using the ACF relationship field. Employees also have a true/false field (em_active). Now in the archive of companies I need to add filtering from facetwp. When enabled, the checkbox should show only those companies whose employees have the field set to true.

I found such a snippet, but it seems it doesn't quite fit me or I won't be able to give it a mind)))

add_filter( 'facetwp_index_row', function( $params, $class ) {
    $name = $params['facet_name'];
    $cpu_id = (int) $params['facet_value'];

    if ( 'cpu_frequency' == $name ) {
        $params['facet_value'] = get_field( 'frequency', $cpu_id );
        $params['facet_display_value'] = get_field( 'frequency', $cpu_id );
    }
    elseif ( 'cpu_cores' == $name ) {
        $params['facet_value'] = get_field( 'cores', $cpu_id );
        $params['facet_display_value'] = get_field( 'cores', $cpu_id );
    }

    return $params;
}, 10, 2 );

Help, please)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source