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)

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

$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:

How to use custom PHP code?

PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info

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 );

More examples

See also

Last updated: May 2, 2023