I am hooking onto the acf/save_post action, and printing out the number of queries that WordPress is executing upon a post update. I found that on one of my posts, the number of queries exceeds 6000!
I found this but simply executing the following code:
My setup is a main repeater field. That repeater field contains like 10 fields inside of it. 2 of those fields are nested repeater fields. My main repeater has like 30 items, and my nested repeaters might have 2-10 items.
I am using get_field and get_sub_field on each field.
Why the high number of queries to update a single post? Does ACF not pull from WP cache when polling fields?
As far as I know, ACF does pull from wp_cache, but the cache only contains values for custom fields that have already been used one. Each time you use an ACF function to get a field value it will generate several queries.
If you’re talking about the back end when updating a post, there really is not any way to reduce the number of queries needed to update all of the fields. ACF is a great plugin but it is uses WP function for updating values so with a lot of fields the update process will be slow, and can even time out if you have too many. I’ve found that this is important to keep in mind when designing an admin page and how it will work.
On the front end you may be able to reduce the number of queries to get the information by forcing WP to get all of the meta values for a post before trying to access any of them. You can do this by calling get_post_meta() without giving a field name get_post_meta($post_id);https://developer.wordpress.org/reference/functions/get_post_meta/
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users