How to Trigger the Indexer Programmatically

During a process called indexing, FacetWP analyzes your site and stores facet data into a custom database table for quick lookups.

After the initial index, FacetWP automatically re-indexes individual posts whenever they’re saved via the admin UI.

As a developer, you may need to programmatically trigger the indexer (such as when doing nightly imports). Fortunately, this is as easy as calling the following method:


The above code will re-index your entire site. If you want to re-index a single post instead, then simply set the $post_id parameter.

$post_id = 12345;
FWP()->indexer->index( $post_id );