Did some tests and found out it was
get_fields(); function causing this amount of queries. This is a bit confusing behavior. Reading documentation, I expected this function to do smth like
SELECT * FROM wp_postmeta WHERE post_id = $ID. One query, run only once and cache results. The
post_id column is index so it would be fast even with millions of rows. Just tested it – takes 0.0005s to complete, returns ALL custom fields associated with post, each ACf field twice – with and without underscore. Instead, it looks like this function gets all keys and runs a separate query for every key to get its value.
In documentation there’s a recommendation to use this function if:
…if you have a large amount of fields which you would prefer not to code independently.
If this function produces hundreds of queries, using it with large amount of fields will be a suicide.
Am I still getting this wrong?
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!