I know this is a couple or 3 months old and not sure if you found a resolution or not, but, I doubt a simple counter
j=1; j+=1 would have anything to do with it. I would change it to
j++, although that should not effect anything.
The main issue is most likely the image and gallery fields returning the image arrays. The more image sizes you have on the site the slower this is going to be.
When it comes to image fields, if you’re worried about performance, you are better off either returning just the ID for each image or getting the unformatted value from ACF and then using core WP functions to get the only the information you need about each image. The image array is going to have a lot of image data that you’ll never use.
You can get unformatted data from ACF by supplying
false as the 3rd argument
get_field('field_name, false, false);` the second false gets values for the current post.
wp_get_attachment_image_src($image_id, $size); to get the image info.
get_post_meta($image_id, '_wp_attachment_image_alt', true); to get the alt text.
get_post_field('post_excerpt', $image_id); to get the caption
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!
© 2022 Advanced Custom Fields.