→ facetwp_index_row

Overview

FacetWP uses a custom database table to store values for all facets. This filter lets you modify what gets saved to this table during the indexing process.

Parameters

  • $params | array | An associative array of data to be indexed (see below)
  • $class | object | The indexer class (e.g. use $class->insert() to manually add rows)

// The keys correspond with columns in the `facetwp_index` table
$params = array(
    'post_id' => 123,
    'facet_name' => 'my_facet',
    'facet_source' => 'tax/category',
    'facet_value' => '45',
    'facet_display_value' => 'My Test Category',
    'term_id' => 0,
    'parent_id' => 0,
    'depth' => 0
);

Each $params element corresponds with a column in the facetwp_index table.

Usage

// Save date in "Jan 1, 2014" format
add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'my_date' == $params['facet_name'] ) {
        $raw_value = $params['facet_value'];
        $params['facet_display_value'] = date( 'M j, Y', strtotime( $raw_value ) );
    }
    return $params;
}, 10, 2 );

Other Notes

  • facet_value is used for the URL / permalink
  • facet_display_value is used as the label (front-end)
  • To bypass indexing for the current row, simply return false.