FacetWP doesn’t automatically index content added via the WP All Import plugin (and the free version).

Fortunately, there are two hooks that can be used to allow FacetWP to automatically detect and index imported posts.

These two hooks work when doing manual imports, cron imports, scheduled imports, and WP-Cli imports. They work in both the free and the pro versions of WP All Import.

Trigger re-indexing of individual posts

To re-index each individual posts after it has been imported, add the following code to your (child) theme’s functions.php:

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

// Re-index each post after it has been imported function facetwp_reindex_post( $post_id ) { if ( function_exists( 'FWP' ) ) { FWP()->indexer->index( $post_id ); // Re-index the currently saved post } } add_action( 'pmxi_saved_post', 'facetwp_reindex_post' );

Trigger a full re-index after an import

If you’re importing large datasets and would rather re-index the entire site after an import, use the following snippet instead:

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

// Run a full re-index of all posts after the import has finished function facetwp_reindex_all_posts( $import_id ) { if ( function_exists( 'FWP' ) ) { FWP()->indexer->index(); // Run a full re-index of all posts } } add_action( 'pmxi_after_xml_import', 'facetwp_reindex_all_posts' );

Prevent duplicate results with imported posts

If you are regularly importing posts, be aware of the fact that imported posts often end up having the exact same post date.

This can lead to issues when queries are using the post date in their orderby query argument. Adding to the problem is that WordPress by default will order queries by post date.

In this scenario with multiple posts sharing the same date, if no specific order is set for a query, or if it is intentionally set to date, MySQL will not have a fallback and will often sort erratically. This can lead to duplicate results in your listing, most visibly when you are using a Pager/Load more facet or a Sort facet.

The problem can be easily fixed by setting something else than date in the orderby argument of your queries. Or by introducing a secondary, fallback sorting method.

See also