Forked from jchristopher/searchwp-customizations.php
Last active
March 3, 2021 14:12
-
-
Save mihdan/85e428d9039bbcd88374e9653a13e72c to your computer and use it in GitHub Desktop.
How to Integrate SearchWP with Wp All Import
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 | |
/** | |
* WP All Import SearchWP PRE-import routine | |
* | |
* @link https://searchwp.com/documentation/knowledge-base/content-imports/ | |
*/ | |
add_action( 'pmxi_before_xml_import', function( $import_id ) { | |
\SearchWP::$indexer->pause(); | |
// If you do not want SearchWP to process all of the edits | |
// made by the import process, uncomment the following hook. | |
// add_filter( 'searchwp\sources', '__return_empty_array', 99999 ); | |
}, 10 ); | |
/** | |
* WP All Import callback that runs for each imported entry. | |
* Purge that post from the SearchWP index. | |
* | |
* NOTE: This is not necessary unless you have uncommented the hook | |
* in the pmxi_before_xml_import action above. | |
* | |
* @link https://searchwp.com/documentation/knowledge-base/content-imports/ | |
*/ | |
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 ); | |
\SearchWP::$index->drop( $source, $post_id, true ); | |
}, 10 ); | |
/** | |
* WP All Import SearchWP POST-import routine | |
* | |
* @link https://searchwp.com/documentation/knowledge-base/content-imports/ | |
*/ | |
add_action( 'pmxi_after_xml_import', function( $import_id ) { | |
\SearchWP::$indexer->unpause(); | |
// If you uncommented the hook in the pmxi_before_xml_import | |
// action above, uncomment the following hook. | |
// remove_filter( 'searchwp\sources', '__return_empty_array', 99999 ); | |
\SearchWP::$indexer->trigger(); | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment