X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

facetwp_facet_sources

Overview

The facetwp_facet_sources filter lets you modify the Data Sources dropdown.

This filter is useful for adding custom data sources, or for modifying the existing data sources (e.g. move certain custom fields into their own <optgroup>).

If you’re adding new data sources, then you’ll likely also need to use the facetwp_index_row filter to control how the data gets saved to FacetWP’s index table.

Parameters

$sources = array(
    'posts' => array(
        'label' => 'Posts',
        'choices' => array(
            'post_type' => 'Post Type',
            'post_date' => 'Post Date',
            'post_modified' => 'Post Modified',
            'post_title' => 'Post Title',
            'post_author' => 'Post Author'
        )
    ),
    'taxonomies' => array(
        'label' => 'Taxonomies',
        'choices' => array(
            'tax/category' => 'Categories',
            'tax/post_tag' => 'Tags'
        )
    ),
    'custom_fields' => array(
        'label' => 'Custom Fields',
        'choices' => array(
            'cf/horsepower' => 'horsepower',
            'cf/mpg_city' => 'mpg_city',
            'cf/mpg_highway' => 'mpg_highway',
            'cf/torque' => 'torque'
        )
    )
);

Note: each array key (posts, taxonomies, custom_fields) is its own <optgroup>. By adding new array keys, you can create your own optgroups.

Usage

Add a new custom field named “my_data”:

add_filter( 'facetwp_facet_sources', function( $sources ) {
    $sources['custom_fields']['choices']['cf/my_data'] = 'my_data';
    return $sources;
});

See Also

Facet Configuration

facetwp_index_row