Best approach for a custom database filling in WP custom post types

I’m a little unsure what “offer WordPress websites for them’ means in terms of implementation. But here are some questions I would ask when approaching this problem:

  • How tightly coupled are the systems? Is this DB and the related WP sites running on the same server?
  • For the DB on a dedicated server, do you have control over the MySQL DB and / or the api that manages it?
  • Do you really need to propagate this to WordPress? Does a JS POST request to the DB (or api) not make sense in this situation?

Same Host

The easiest thing would be if the dedicated MySQL DB is on the same machine since authentication is already taken care of. Events that happen with the MySQL db could then be pushed to WP using some sort of wp-cli command.

Different Hosts

If these sites are on different hosts, and if you are able to make changes to the dedicated server / api, then I would explore a solution where you:

  1. Create an endpoint in WordPress (Rest API) which then updates the WP DB as needed.
  2. Extend the dedicated server so that it issues a POST request to that endpoint

The main challenge here is authentication and security. It’s not impossible but I’ve never really liked working with oAuth. I like this solution best though because changes are propagated out almost immediately, so you don’t have differences between the two dbs.

Different Hosts, access only to WP

If you are not able to make changes to the dedicated server, then I think you are left with some sort of cron solution. WordPress has a pretty good HTTP API so that you don’t have to do the heavy lifting of generating a full request and dealing with weird edge cases. The main drawback is that unless you are checking fairly often, there might be a difference in the number stored in the dedicated DB and the number stored in the WP DB.

Hope that helps clarify your thinking!