Home Forums ACF PRO Better way to update multiple fields (update_field()) Reply To: Better way to update multiple fields (update_field())

  • That depends on how good you are at MySQL queries and using $wpdb

    for example a single query can insert multiple values all at once

    INSERT INTO wp_postmea (post_id, meta_key, meta_value) VALUES ("1", "field_1", "value_1"),("1", "_field_1", "field_0123456789"),..... etc.

    If you’re interested, you’d need to do a couple things.

    1) the best thing you can do is to delete all the meta values for the post first. The main reason that WP is so slow at inserting/updating post meta is that it checks every value to see if it already exists for the post or not and then either updates or inserts as needed. By deleting them all first you remove the need to check. You can’t use an INSERT IGNORE query because there’s nothing to indicate unique values in the postmeta table.

    2) you need to make sure you insert the ACF field references for each field as well as the value, like the second value in my example.