I have the following code attached. The problem is that it will republish all of the posts sometimes, instead of updating them if they already exist and deleting individuals ones that shouldn't be there anymore.
I need it to do the following. When you login into the admin and should run once a day (cron job? WP, CRON is setup on plugin activation. Once set up, it keeps waking up based on configured cycle until remove through plugin deactivation.)
- check third party api url
- if current post are missing from the api, delete them
- if a post is missing from the admin that is in the api, add it
- if a post is currently there, update it
- no longer needs to be done with admin-ajax, this will not be called from js, should all run as is
- do not republish all the posts (this is what my code will currently do after x-amount of time)
- need a way to set a meta value or something that will prevent this from happening
- There is Job ID in API result. It's unique, and should store it when creating new WP post from API result and then next day, use the Job ID to identify which posts to update.
- Should also not use 'file_get_contents' function. Wordpress has a transport transparent Remote API which is specially coded for making remote http calls.