So I am basically trying to create my own version WP All import plugin. But less fancy :) I just want to import data from a given XML file and create/update a custom post type. In this case its job postings so I have a custom post type defined as "job_post". I got it to import all the feed data and create new posts but I am kind of struggling with the updating process. If there are any changes in any of the job posts in the feed then I have to find that specific job post in the custom post types I create and update the changes. Also have to delete posts that are no longer in the feed.
So whats the best performant way of doing this? The feed has upwords of 150 jobs and I have noticed that it takes a while to create new custom posts with the feed data. I will add my function that I use to create new posts below:
public function create_job_posts( $jobs ) { $job_post_id_list = []; foreach($jobs as $job) { $job_post = $this->get_job_post_properties( $job ); // Create posts $post_id = wp_insert_post( $job_post['post_general'] ); // Create post meta foreach($job_post['post_meta'] as $post_meta_key => $post_meta_val) { update_post_meta( $post_id, $post_meta_key, $post_meta_val ); } // Create post taxonomies foreach($job_post['post_taxonomies'] as $post_taxonomy_key => $post_taxonomy_val) { wp_set_object_terms( $post_id, $post_taxonomy_val, $post_taxonomy_key ); } $job_post_id_list[] = $post_id; } update_option( self::JOB_POST_LIST_SLUG, $job_post_id_list ); }
No comments:
Post a Comment