Overview

FacetWP has an automatic indexer that performs a single re-index when an individual item (a post, page, and category or term name/slug) is edited or saved. This keeps the index up to date automatically without having to worry about it, and without putting the potentially heavy burden of a full re-index on your site.

With this hook, you can temporarily or permanently disable this automatic (re-)indexing process.

This can be useful if you prefer to re-index manually with the Re-index button. Or if you want to run the indexer programmatically, directly with PHP, with a non-recurring WP-Cron event, periodically with the Schedule Indexer add-on (which works with WP-Cron), or with WP-CLI/server cron. Other reasons for using this hook could be if you want to (temporarily) pause automatic indexing when importing content, if you are testing custom indexing code, or if you want to disable automatic indexing for certain types of content.

Disable automatic indexing.
Disable automatic indexing.

Note that automatic indexing can also be disabled with the “Enable automatic indexing” setting (introduced in version 4.3.4). This setting is enabled by default. When disabled, it does exactly the same as using the hook in your functions.php.

Parameters

  • $is_enabled | boolean | Whether FacetWP’s automatic indexer is enabled

Disable automatic indexing

Add the following code to your (child) theme’s functions.php to entirely disable automatic indexing:

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_is_enabled', '__return_false' );

Conditionally disable automatic indexing

The following example disables automatic re-indexing for Advanced Custom Fields field groups:

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_is_enabled', function( $enabled ) { if ( isset( $_POST['action'] ) && 'editpost' == $_POST['action'] && isset( $_POST['post_type'] ) && 'acf-field-group' == $_POST['post_type'] ) { return false; } return $enabled; });

Disable automatic indexing for a file

If you are adding posts or terms programmatically, with the intention to index the new/changed posts programmatically at the end of the process, you may run into trouble with FacetWP’s automatic indexer being triggered along the way.

For example, if you are using wp_set_object_terms to set new terms, which will trigger an automatic re-index of the post at that point. In this situation, you can disable the automatic indexing for your file, like this:

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_is_enabled', function( $enabled ) { if ( 'my_file.php' == FWP()->helper->get_uri() ) { // Change my_file.php return false; } return $enabled; } );

More examples

See also

Last updated: November 25, 2024