im currently developing a plugin that will read an external xml, and convert the data to a custom post type. Each post needs around 50-60 meta_fields. Right now im looping through each piece of needed data in the xml and running a update_post_meta() on each of them. This turns out to be very inefficient because each update_post_meta results in a separate request, which in my case results in a server timeout when the xml has a lot of data.
imagine that the $event[‘meta’] has 50 fields, and I need to run all 50 updates on 500 posts in one go.
// add/update meta fields
foreach ($event['meta'] as $meta_key => $meta_value) {
update_post_meta( $post_id, $meta_key, $meta_value );
}
Is it possible to combine all the meta updates into one request? maybe in combination with the wp_insert_post() ?
its important that it must create a meta field if it doesn’t already exist, while updating it if it does, much like update_post_meta does.
1 Answer
Do all insert manually via wpdb (SQL). you can do multiple inserts with one sql statement. the wp_post_meta is very simple built.