Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Last active March 9, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searchwpgists/1354653ed6f9181dce9da96e23da8d35 to your computer and use it in GitHub Desktop.
Save searchwpgists/1354653ed6f9181dce9da96e23da8d35 to your computer and use it in GitHub Desktop.
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