Home › Forums › ACF PRO › Add_row and add_sub_row running slowly › Reply To: Add_row and add_sub_row running slowly
Whether you add all of the rows using update_field(), or you add each row, the problem is the same.
ACF uses the built in WP function update_post_meta() or one of the variant functions that does the same thing. This function can only update a single custom field and it causes from 2 or 3 queries to be run each time it is called. First it sees if the meta_key/meta_value exists and then it inserts or updates depending on that. To be honest, I’m not sure what triggers the 3rd query and it does not always happen. In addition to this ACF adds a field key reference meta_key and this update causes another 2 or 3 queries to be run. So you have a total of 4 to 6 queries for every field updated.
This is a limitation in ACF, but the root cause is a limitation in WP due to the way it handles custom fields/meta values.
Unfortunately, there isn’t workable solution. SQL does allow inserting multiple rows to a table in a single query, but doing so causes other issues, like the meta cache not being updated correctly. The only real solution would be to construct custom queries for inserting the values with all the correct meta_key/meta_value pairs and then directly insert the values to the DB using SQL rather than allowing WP to handle the work.
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!
🤔 Curious about the ACF user experience? So are we! Help guide the evolution of ACF by taking part in our first ever Annual Survey and guarantee you’re represented in the results. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 8, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.