→ Integrating FacetWP with WP All Import

If you’re using WP All Import to pull in content, you’ll notice that FacetWP won’t¬†automatically index it. Fortunately, it’s possible to trigger indexing using¬†the pmxi_saved_post filter.

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

The above filter re-indexes individual posts. 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' );

Add this code to your theme’s functions.php or within a custom plugin.