• I need to create new posts in an existing WP site using data returned from an external API call via a Cron job on the same server/domain as the WP site.
    I can see that XML-RPC would be the way to go for this but I have not been able to find out how to also include tags and categories when creating the new posts.
    Matching tags and categories are already present in the WP site.
    So, I call an API and with the returned data I will format it ready for inserting into the wp_posts table. Part of the API data will also provide me with what categories the new post should be assigned so I need to include this with the new post creation function somehow.
    Also, should I be concerned that the API may return in excess of 5,000 new posts?
    Imagine you were importing library books from your local libraries API into your WP site as new posts and each had to be categorised appropriately, that’s basically what I need to do. And this API call has to be run daily.

    Any help much appreciated.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You seem to be convinced that XML-RPC is the way to go. I can’t speak for that interface, but I’d like to review some other options available to you for reconsideration.

    WP REST API – IMO the JSON format used by this plugin is much easier to work with than XML. This plugin is being seriously considered for incorporation into core.

    WP-CLI – Installing this on your server allows you to directly execute WP functions from your CRON script just like you would execute any other command line function. IMO this makes the most sense for CRON jobs.

    wp_schedule_event() – You could use this instead of a CRON job. As it executes within the WP environment, you have full access to all WP functions unimpaired by some other interface. Unlike CRON jobs, it does require some site visit to trigger the event. For any site open to search spiders this should not be a problem, even if there’s no human traffic to speak of. It does mean the event may not fire exactly on schedule, but delayed until the next request comes in after the scheduled event, usually just a few minutes.

    5000+ posts shouldn’t be a problem, unless you’re saying 5000 per day! It ultimately depends on how many other sites/DBs are being run on the same server and the traffic load. It could be stretching the limits of shared hosting, but shouldn’t be a problem for VPS and better.

Viewing 1 replies (of 1 total)
  • The topic ‘Create new posts from external website.’ is closed to new replies.