facetwp_facets

Overview

Dynamically register new facets.

Parameters

  • $facets | array | An array of existing facets

Available settings

Every facet has a label, name, and type (and most facet types have a source). The exact list of settings depends on the facet type.

The best way to see the available settings for any given facet type is by exporting a sample facet (Settings > FacetWP > Settings and click the “Backup” tab).

Once you have the export code (it’s in JSON format), paste it into http://jsonviewer.stack.hu/ to see the settings visually.

Usage

The following code adds a search facet named my_search:

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

This code adds a checkboxes facet named categories:

add_filter( 'facetwp_facets', function( $facets ) {
    $facets[] = [
        'label' => 'Categories',
        'name' => 'categories',
        'type' => 'checkboxes',
        'source' => 'tax/category',
        'parent_term' => '',
        'hierarchical' => 'no',
        'orderby' => 'count',
        'count' => '20',
        'show_expanded' => 'no',
        'ghosts' => 'no',
        'preserve_ghosts' => 'no',
        'operator' => 'and',
        'soft_limit' => '5'
    ];
    return $facets;
});

More examples