Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to Integrate SearchWP with Content Imports
<?php
// Disable SearchWP's automatic integration with WP All Import.
add_filter( 'searchwp\integration\wp-all-import', '__return_false' );
add_action( 'pmxi_before_xml_import', function( $import_id ) {
\SearchWP::$indexer->pause();
}, 10 );
add_action( 'pmxi_saved_post', function( $post_id ) {
$source_name = \SearchWP\Utils::get_post_type_source_name( get_post_type( $post_id ) );
$source = \SearchWP::$index->get_source_by_name( $source_name );
// Mark this to be dropped after the import has finished.
\SearchWP::$index->drop( $source, $post_id );
}, 10 );
add_action( 'pmxi_after_xml_import', function( $import_id ) {
\SearchWP::$indexer->unpause();
// Process all entries marked to be dropped.
\SearchWP::$index->unpause();
\SearchWP::$index->trigger();
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment