When is it better to use get_fields over multiple get_field.
The documentation just says a large number of fields. So 10 fields,20 fields,100 fields?
Has anyone done any testing on this?
I go by the first part of that description
You should only use this function when you do not know the fields which which will be appearing on a template…
and the part in bold of the second part
…or if you have a large amount of fields which you would prefer not to code independently.
Since I always know what fields will appear and I prefer to code them independently I don’t use the function. Also, most of the time I don’t want to use a simple loop to display the fields and I’ll likely just need to access the elements of the array instead of using
get_field() where I’ll be using the value.
I might use this for a simple list of field content when the order it’s entered is the order I want to display it in.
I’m asking this because I’m using ajax to get/post and manipulate around 10-15 fields of a post that has 25-30 fields in total. Right now I’m using a mix of both in my plugin and want to stick to one way for consistency.
In wordpress I observed ajax requests if not coded properly end up using a lot of resources. So I was hoping there was some statistics or comparisons of some kind.
If you’re worried about how many DB calls are made for the requests then you could do both, forcing ACF to get all the fields and then getting each one separately. Once the fields are loaded once they values are stored in the WP cache so later calls to get the same field will not generate another DB call.