Home › Forums › General Issues › What's faster? › Reply To: What's faster?
(A) will be faster if you have a significant number of fields to get.
I actually use a combination of the two.
$allPostMeta = get_post_meta($id);
$item1 = get_field('item1', $id);
$item2 = get_field('item2', $id);
$item3 = get_field('item3', $id);
// […]
$itemN = get_field('itemN', $id);
The reason is that the first statement makes WP get all of the meta values and put them in a cache, from that point on get_field() gets values from the WP cache and the ACF functions are easier for most people to use than trying to navigate a complicate array of meta data, especially if it might contain things like repeaters.
As for gallery fields, and image fields, If you have many images then returning the image ID and getting specific image information based on the ID with standard WP functions like wp_get_attachment_image_src() https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ will provide better performance than returning an image object/array in ACF.
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.