Skip to content

Instantly share code, notes, and snippets.

@trey8611
Created March 12, 2022 14:59
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 trey8611/ac4f11291d8473c9788f24d48bdcf8a8 to your computer and use it in GitHub Desktop.
Save trey8611/ac4f11291d8473c9788f24d48bdcf8a8 to your computer and use it in GitHub Desktop.
[Chain Cron Imports / Exports Together] Sequential Cron Imports/Exports

Cron Job Imports: http://www.wpallimport.com/documentation/recurring/cron/.

If you want to run imports or exports sequentially, you can use this workaround:

  • Set up the "trigger" cron job and "processing" cron job for the import/export that should run first.
  • Set up "processing" cron jobs for all of the imports/exports that are going to run.
  • Modify the following code by adding your own URL and import/export IDs then save the code inside the Function Editor:
function my_run_cron_after_import( $import_id ) {
    // This is how the imports are chained together...
    // For example, after import ID '1', import ID '2' will be called.
    // You can adjust/add/remove import IDs in the array as needed.
    $chain_map = array(
        '1' => '2',
        '2' => '3',
        '3' => '4'
    );
    if ( array_key_exists( $import_id, $chain_map ) ) {
        $id = $chain_map[ $import_id ];
        $trigger_url = "http://helpful-barracuda.w5.wpsandbox.pro/wp-cron.php?import_key=FReKvO&import_id=" . $id . "&action=trigger";
        $trigger_response = wp_remote_get( $trigger_url );
    }
}
add_action( 'pmxi_after_xml_import', 'my_run_cron_after_import', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment