Support

Account

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.