0

I've been working with an external API to pull in data and create what's essentially a job board via custom post types with wp_insert_post. My concern is that once these jobs/custom posts are removed from the database, they'll remain on the WP site without explicit removal.

How can I best utilize wp_delete_post to check against the API for a non-match and subsequently delete the custom post?

I'm currently running the following code to fetch data for the posts:

function populate_jobs() {  

    $registerJobs = json_decode($url, true);

    foreach($registerJobs['jobs'] as $job){

        //Variables

        if (!get_page_by_title($jobId, OBJECT, 'jobs')) :

            $job_post = array(

                //Data for posts

                )
            );

            wp_insert_post($job_post);

        endif;

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.