X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

How FacetWP’s Indexer Works

Indexing is the process of storing facet data into a custom database table. It allows FacetWP to retrieve data very quickly and efficiently.

How is the indexer triggered?

If facets are added, we ask that users press the Re-index button within FacetWP’s admin UI. This completely rebuilds the index table.

When you save settings in FacetWP’s admin that require a re-index of your content, the re-index button will be highlighted to remind you to run the re-index.

FacetWP automatically indexes changes when posts or taxonomy terms are updated.

The facetwp_index table

FacetWP adds one database table: facetwp_index. This table contains all the information needed to generate the facets.


How does the indexer work?

When the Re-index button is clicked, FacetWP first retrieves all post IDs that should be indexed. It uses WP_Query, and the query arguments are customizable.

FacetWP then loops through the array of post IDs. For each, it loops through all available facets and saves applicable values. Below is a pseudocode example:

foreach ( $post_ids as $post_id ) {
    foreach ( $facets as $facet ) {
        index_values( $post_id, $facet );

The values for each row can be modified using the facetwp_index_row filter.

Indexing progress

When indexing, you’ll see a progress bar. This serves two purposes: it keeps you informed, while also pinging the server to check for a stalled indexer.

While the indexer is running, the re-index button text changes to Stop indexer. This will stop any progress, but remember that the index will remain incomplete until you re-index again.

Keep the FacetWP settings page open until you see the Indexing complete message.

Built-in resuming

The indexer can stall for various reasons: the server ran out of memory, power outage, etc. The important part is that the indexer picks up where it left off, which is exactly what happens.

The indexer frequently updates information about itself:


If the “touch” date (see above) is more than 60 seconds old, FacetWP assumes the indexer has stalled, and starts a new process. Since the “retries” value will have increased, any old processes will automatically die if they haven’t already.

Other index actions

Version 3.2.0 introduced indexing stats:

Show indexer stats provides information about FacetWP’s index table.

Show indexable post types lists all post types that will be indexed. If a desired post type is not in the list, make sure that exclude_from_search = FALSE (re-index afterwards). Alternatively, you could use the facetwp_indexer_query_args filter to force the post type to be indexed.

Purge the index table deletes and re-creates the facetwp_index database table. This can be helpful in resolving database migration issues.