→ facetwp_render_output

Overview

This filter lets you modify the final output array, before it’s converted to JSON and returned to the client (via AJAX).

Parameters

  • $output | array | An associative array of output data (see below)
  • $params | array | An associative array of input parameters (see below)

<?php
$output = array(
    'facets' => array(
        'the_facet_name' => 'HTML output',
        'another_facet' => 'HTML output',
    ),
    'template' => 'HTML string',
    'settings' => array(
        'the_facet_name' => array(
            'setting1' => 'value'
        )
    ),
    'pager' => 'HTML output',
    'sort' => 'HTML output',
);

$params contains the data (selected values, etc.) passed in client-side from AJAX.

<?php
$params = array(
    'facets' => array(
        array(
            'facet_name' => 'the_facet_name',
            'selected_values' => array( 1, 2, 3 ),
        ),
        array(
            'facet_name' => 'another_facet',
            'selected_values' => array( 4, 5 ),
        ),
    ),
    'template' => 'my_template',
    'http_params' => array(
        'uri' => 'the/page/url'
    ),
    'extras' => array(
        'sort' => 'default',
        'pager' => true,
    ),
    'paged' => 1
);

Usage

In this example, we will modify the “start” setting for a slider facet. On first load, the slider will only show items with a price between 500 and 1000.

function my_facetwp_render_output( $output, $params ) {
    $output['settings']['price']['start'] = array( 500, 1000 );
    return $output;
}
add_filter( 'facetwp_render_output', 'my_facetwp_render_output', 10, 2 );