Populate custom post type/custom fields from an external database

So the best way here would be for your other system to “call” WordPress any time something changes… You could build a WordPress plugin that listens for a specific ajax call and upon receiving the new data, it could create / update the custom post type in your WordPress site.

Some things to remember:

  • Make sure you have some kind of handshake mechanism (like a private key or something) otherwise anyone could start creating posts in your system!
  • Make sure to pass on a unique ID for each record, that you will save as a custom field in WordPress, so you can update existing records instead of creating new ones.

A less elegant solution, would be for WordPress to poll your system every so often, and ask it for anything new. In this case, your WordPress plugin would need to save the date of its last request, so it can ask your main system for any changes since that last call. Your main system would return a list of updated record, and the plugin could create/update each custom post accordingly.

To poll from WordPress, your plugin can install a schedule for wp-cron

This is going to be a bit less elegant and efficient because WordPress will be asking every so often if anything’s changed. This means it will potentially ask too often and waste cycles, (if things don’t change often in the main system) or not often enough, and your WordPress data will be stale.

Hope this helps!