Combining Facet Sources

By default, some facet types (such as autocomplete) only support a single data source. With a bit of custom code, we can trick FacetWP into indexing multiple sources.

Let’s assume we want a full_name facet that pulls data from “First name” and “Last name” fields.

First, create a facet named full_name and set its data source to the “First name” field.

Next, add another facet named last_name and set its data source to the “Last name” field.

Finally, add this code to trick FacetWP into indexing last_name values into the full_name facet:

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'last_name' == $params['facet_name'] ) {
        $params['facet_name'] = 'full_name';
    }
    return $params;
}, 10, 2 );