facetwp_facet_display_value

Overview

Modify the display value (i.e. label) for specific facet choices.

Parameters

  • $label | string | The facet choice label (text or HTML)
  • $params | array | An associative array of facet settings (see below)

$params = [
    'selected' => false, // TRUE or FALSE
    'facet' => [
        'name' => 'vehicle_type',
        'label' => 'Vehicle Type',
        'type' => 'radio',
        'source' => 'tax/vehicle_type',
        // + other facet-specific settings
    ],
    'row' => [
        'id' => 123,
        'post_id' => 42,
        'facet_name' => 'vehicle_type',
        'facet_value' => 'suv',
        'facet_display_value' => 'SUV',
        // + other columns from the "facetwp_index" DB table
    ]
];

Usage

Display icons instead of labels. The icon names are based on each facet choice’s raw value (e.g. “car”, “truck”, “suv”):

add_filter( 'facetwp_facet_display_value', function( $label, $params ) {

    // only apply to a facet named "vehicle_type"
    if ( 'vehicle_type' == $params['facet']['name'] ) {

        // get the raw value
        $val = $params['row']['facet_value'];

        // use the raw value to generate the image URL
        $label = '<img src="/wp-content/themes/yourtheme/images/{val}.svg" alt="{val}" />';
        $label = str_replace( '{val}', $val, $label );
    }
    return $label;
}, 10, 2 );

More examples