How to Register Facets Programmatically

FacetWP supports registering facets in code using the facetwp_facets filter.

Usage

The following example will add a new search facet.

function mytheme_register_facets( $facets ) {
    $facets[] = array(
        'label' => 'My Search',
        'name' => 'my_search',
        'type' => 'search',
        'search_engine' => '',
        'placeholder' => 'Enter keywords',
    );
    return $facets;
}
add_filter( 'facetwp_facets', 'mytheme_register_facets' );

We’re simply adding a new element to the $facets array. Every facet has a label, name, and type property (and most also have source).

To learn more about this filter and to see each facet type’s available settings, please visit the documentation page.