Scheduling Imports Using Cron Jobs

Scheduling Imports Using Cron Jobs

Each time the cron is run, WP All Import will download your XML or CSV file from the specified URL and update, delete, and create posts on your site according to your settings.

To set up a recurring import using cron jobs, specify the URL to your XML or CSV file on the Import Settings page.

Then, visit the Scheduling Options link on the Manage Imports page to open the Scheduling Options Popup.

You will need to choose the 「Manual Scheduling」 option here:

Manual Scheduling

Each import has two cron URLs – a trigger URL, and a processing URL.

The trigger URL will look something like this:http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger

The processing URL will look something like this:http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=processing

You can find your secret key on the All Import -> Settings screen, and the import ID on the Manage Imports screen.

If you want to run your import every 24 hours, you should run the trigger URL every 24 hours. If you want to run your import once per week, you should run the trigger URL every week.

The processing URL should be run every two minutes because it may not finish your import in one run. The reason is that many hosts have maximum script execution times in place, so its only possible for the processing script to finish only a small percentage of your import before it is timed out.

If this is the case and the processing script is run again after two minutes, it checks to see if your import is finished, or if there』s still work to be done. If there』s work to be done, it will import posts for as long as it can, or two minutes, whichever is longer.

Then, on the next run of the processing script, it will see if more work needs to be done on the import – and if so, it will do it. If not, it will 「untrigger」 the import. And now the processing script will have no effect until the import is triggered again by the next run of the trigger script.

Setting Up Cron Jobs

The instructions for setting up cron jobs vary across hosts. Commonly, you can do it in your web hosting control panel.

To create a cron job that hits the cron URLs, commonly the wget command is used. Examples are on the Manage Imports -> Cron Scheduling screen of WP All Import.

Below are a few cron command examples (not all options work with all hosts, ask your host for help as needed):

wget --spider "http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger&rand="$RANDOM

wget -q -O - "http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger&rand="$RANDOM

curl "http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger&rand="$RANDOM

lynx "http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger&rand="$RANDOM

To ask your web hosting provider to set up the cron for you, use this e-mail template:

Hi Support,

Please set up two cron jobs.

CRON JOB 1Fetch this URL every 24 hours: http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=trigger

CRON JOB 2Fetch this URL every 2 minutes: http://YOUR-WEBSITE.com/wp-load.php?import_key=[YOUR_SECRET_KEY]&import_id=[YOUR_IMPORT_ID]&action=processing

Thanks,Your Name

If your web host doesn』t have a cron feature, you can use an external service like EasyCron.

Call Cron URLs from the Command Line

You can call the WP All Import and WP All Export cron URLs from the command line. This may be necessary if your site's configuration won't allow inbound calls to the regular cron URLs.

It'd look something like this:

/path/to/your/php-cgi /path/to/yourwordpressinstall/wp-load.php import_key=ABC123 import_id=5 action=trigger
/path/to/your/php-cgi /path/to/yourwordpressinstall/wp-load.php import_key=ABC123 import_id=5 action=processing

Note: The php-cgi binary must be used or the parameters won't be passed correctly.

Manual Record Matching

Manual Record Matching

WP All Import can import data to posts that already exist on your site, even if they were manually created instead of imported by WP All Import.

You need something in your import file that WP All Import can use to 「match」 the 「records」 in your import file to the posts that already exist on your site – that』s why it』s called Manual Record Matching.

When importing into existing records, you can specify which data WP All Import will update or overwrite, and which will be left alone.

Follow along with the below example to get a complete understanding of how to import data into existing posts on your site.

Example – Updating Multiple Property Listings With New Prices

I have a few property listings with outdated prices.

Example Properties

I have a CSV file with the MLS numbers of the properties, and the new prices.

CSV File

I』ve entered the MLS number of each property in my theme, so we can use the MLS number as the 「matcher」 so that WP All Import knows which price should be assigned to which property.

MLS Number

To do the import, upload your CSV in Step 1, and choose Existing Items.

Step 1 Existing Items

Continue to Step 2 and then to Step 3. In Step 3, set the price Custom Field to the price from your file.

Setting the price

The only field we want to import data to is the price. So just leave all the other fields blank. WP All Import will warn you that your post title and content are blank, but that』s fine – you can continue anyway. We don』t want to update the title or content here, just the price.

Now it』s time for the most important part – telling WP All Import how to match the records in our CSV file with the existing property listings already on our site. We』re going to match by the MLS number – since we have the MLS number in both places – on our site, and in our file.

Choose 「Match by Custom Field」 and click in the Name box to see a dropdown list of Custom Fields available to match by. Then choose 「mls_value」 – the Custom Field name the theme uses internally for the MLS field.

Record Matching

Then drag & drop the MLS column in your CSV file to the Value textbox.

MLS Value

Now, for each record in your file, WP All Import will look for a property on your site with an mls_value Custom Field that equals {mlsno[1]} from your file, and then import the price to it.

To ensure WP All Import only imports the price, and doesn』t overwrite the title, content, and other fields we left empty with blank values, we specify which data points we wanted updated, and which we want ignored.

Choose which data to update

Here』s the result after running the import – our 3 posts were updated with the new prices.

Import Summary

Data Updated