If you are seeing a different number of queries being done when using get_field() as apposed to get_fields(), there are some things you can to.
The first thing is to call
get_post_meta($post->ID), this will cause all of the meta values for a post to be loaded into the WP cache and then any additional calls will not create additional queries.
get_fields() will cause the same thing to happen as the first option.
Once this is done you don’t really need to use the array that’s returned, you can just use
get_field('field_name') after that and these will get values from the cache and not do an additional query.
I’m not really sure why you’d be seeing a difference in the number of queries unless you’re getting values from another post, not the current post in “The Loop”. Usually, I’ve found that when setting up a post WP automatically gets all the post meta values automatically.
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!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.