→ facetwp_facet_render_args

Overview

This filter lets you modify the data passed to a facet’s render() method. This is useful if you need to programmatically alter the selected values.

Parameters

  • $args | array | An associative array of facet render arguments (see below)

$args = array(
    'facet' => array(
        'label' => 'Model Year',
        'name' => 'model_year',
        'type' => 'checkboxes',
        ...
    ),
    'where_clause' => 'AND post_id IN (18670,18671,18672,18673,18674)',
    'selected_values' => array(
        '2014',
        '2015',
        '2016'
    )
);

Some facet types also have $args['values'], depending on whether the facet type has a load_values() method.

Usage

Modify the selected values for a specific facet (e.g. model_year)

<?php
function modify_selected_values( $args ) {
    if ( 'model_year' == $args['facet']['name'] ) {
        $args['selected_values'] = array( '2015' );
    }
    return $args;
}

add_filter( 'facetwp_facet_render_args', 'modify_selected_values' );