wpfts_irules_before (Filter)
The wpfts_irules_before
filter in WP Fast Total Search allows developers to add their own indexing rules before the base rules defined in the plugin. This provides the ability to modify or supplement the standard indexing process.
When to Use
This filter is useful when you need to add your own indexing rules that must be executed before the standard rules. For example, you can:
- Add new clusters for indexing data from custom fields or taxonomies.
- Modify how data is processed in existing clusters.
- Add data preprocessing before indexing, such as removing HTML tags or converting text.
Arguments
$irules_base
(array): An array of base indexing rules defined in the plugin.
Return Value
$irules_base
(array): The modified array of indexing rules.
Example (Adding a rule for indexing a meta field)
add_filter('wpfts_irules_before', 'add_custom_meta_field_rule');
function add_custom_meta_field_rule($irules_base)
{
$irules_base[] = array(
'filter' => array( // this rule applies to all posts
'post_type' => 'post'
),
'actions' => array(
array(
'src' => '.my_custom_meta', // extracts the meta field value
'dest' => 'my_custom_cluster', // adds to a new cluster
),
),
'ident' => 'my_custom_irule',
'name' => 'My Custom IRule', // rule name, used for disabling if needed
'description' => 'Indexes the content of "my_custom_meta" meta field.',
'ver' => '1.0', // rule version
'defined_by' => 'My Plugin/Theme Name', // rule source
'ord' => 1000, // execution order (lower value means earlier execution)
);
return $irules_base;
}
Important Notes
- The execution order of indexing rules is determined by the
ord
parameter. Rules with a lowerord
value are executed earlier. - Make sure the rule identifier (
ident
) is unique. - After adding new indexing rules, you may need to rebuild the search index.
- If you modify existing base rules, be careful, as this may affect the plugin’s functionality. It’s better to add your own rules instead of modifying existing ones.
The wpfts_irules_before
filter is a powerful tool that allows developers to extend and customize the WP Fast Total Search indexing process.