Hi @qinisom
ACF Support team here, please note that acf_get_attachment() has no setting of its own, but a few things drive its cost.
For each attachment, ACF fetches the post, the meta, and the alt text. It then builds the sizes array by calling wp_get_attachment_image_src() for every registered image size. Themes and page builders often register a dozen or more sizes, so one image can trigger a lot of work. Multiply that by a gallery or a repeater with images, and it adds up fast.
Things to check, in order of impact:
- Change the field’s Return Format. Image and Gallery fields set to “Image Array” call
acf_get_attachment() for every image. Switch to “Image ID” and render only the size you need with wp_get_attachment_image().
- Use a persistent object cache (Redis or Memcached). Without one, the post and meta lookups hit the database on every page load.
- Trim unused image sizes. Fewer registered sizes means fewer lookups per attachment. Only remove sizes you’re sure nothing uses.
- Check media offload plugins. Plugins that filter attachment URLs can add extra queries or remote calls to every lookup.
- Profile with Query Monitor. It shows which calls repeat and how many queries each attachment costs.
If the function is still slow after checking this, we would love to continue investigating and troubleshooting this issue, please can you create a ticket using our support form and we can look into it further.
Thanks Chris for the prompt response. I will look into the above.
Kind regards,
Qiniso