Home › Forums › General Issues › What's faster? › Reply To: What's faster?
Using get_post_meta($id);
may not be faster for the gallery and images. A gallery stores an array of image ID and all the extra stuff that ACF returns in the array is not stored. So this will only marginally improve performance.
When ACF returns the array it does a query to get all of the attachment posts in the array. It then does quite a bit of work to get the values that it returns in the array, including calling several WP functions that do additional queries.
doing get_post_meta()
at this point won’t improve performance because it’s already ACF has already done most of the queries.
In the case of a gallery field I think something like this would be faster
// the second false returns the unformatted value
$gallery_array = get_feild('gallery', false, false); // 1 query
foreach ($gallery_array as $id) {
get_post_meta($id); // 1 query for each image
}
// at this point all meta data for all images
// should be stored in the cache.
// now just use
$gallery = get_field('gallery');
Although I could be wrong with part of this, I did not follow all of the code all the way through to be sure, I think this would give you your biggest potential for performance gain.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.