Overview

This hook disables FacetWP’s automatic (re-)indexing process.

With this hook in place, re-indexing will not automatically happen when you edit and save posts, pages, and categories/terms, but only when you manually press the “Re-index” button.

This can be useful if you are triggering 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 are 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.

Parameters

  • $is_enabled | boolean | Whether FacetWP’s automtic 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