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 https://codex.wordpress.org/Class_Reference/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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.