FacetWP doesn’t automatically index content added via the WP All Import plugin.

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

Trigger re-indexing of individual posts

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

<?php
function fwp_reindex_post( $post_id ) {
    if ( function_exists( 'FWP' ) ) {
        FWP()->indexer->index( $post_id );
    }
}
add_action( 'pmxi_saved_post', 'fwp_reindex_post' );

Trigger a full re-index after an import

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

<?php
function fwp_import_posts( $import_id ) {
    if ( function_exists( 'FWP' ) ) {
        FWP()->indexer->index();
    }
}
add_action( 'pmxi_after_xml_import', 'fwp_import_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