facetwp_indexer_row_data
Overview
Modify the array of values (for a specific facet) before each is passed through the facetwp_index_row hook and saved into FacetWP’s index table.
Parameters
- $rows | array | An array of associative arrays. The elements of each associative array corresponds to columns in the
facetwp_index
table. - $params | array | Extra helper data (see below)
$params = [
'defaults' => [
'post_id' => 123,
'facet_name' => 'facet_1',
'facet_source' => 'tax/category',
'facet_value' => '',
'facet_display_value' => '',
'term_id' => 0,
'parent_id' => 0,
'depth' => 0,
'variation_id' => 0,
],
'facet' => [
'label' => 'Facet 1',
'name' => 'facet_1',
'type' => 'checkboxes',
'source' => 'tax/category',
// ...
]
];
Usage
Force FacetWP to index the value “Matt” into the first_name
facet for every post:
add_filter( 'facetwp_indexer_row_data', function( $rows, $params ) {
if ( 'first_name' == $params['facet']['name'] ) {
$new_row = $params['defaults'];
$new_row['facet_value'] = 'matt';
$new_row['facet_display_value'] = 'Matt';
$rows[] = $new_row;
}
return $rows;
}, 10, 2 );