-
-
Save searchwpgists/1354653ed6f9181dce9da96e23da8d35 to your computer and use it in GitHub Desktop.
How to Integrate SearchWP with Content Imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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