airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 110 forks source link

Difficulties getting ACF data for attachments/media #310

Open alancwoo opened 5 years ago

alancwoo commented 5 years ago

My attachments have an ACF titled credits

In other post types, images are often pulled in through image or gallery fields, and then pulled into a vue app via the REST API. For example, a project has an image field of banner_image or gallery.

I've read through numerous issues and made several attempts trying to get this credits field to come through in the project -> banner_image object to no avail.

I've tried an array_walk_recursive with add_filter('acf/rest_api/project/get_fields', 'include_nested_acf_data'); and add_filter('acf/rest_api/attachment/get_fields', 'include_nested_acf_data'); as per the lengthy discussion in #109 which is working to fetch ACF data for other related post types.

I've tried adding the recursive plugin with the modification and added my credits field as recommended here: https://gist.github.com/tremppu/bfcb21b1e681f296edcc9079547865bf via #306

I've tried hooking into edit_attachment and acf/save_post

The attachment's direct endpoint does indeed reveal its ACF data but when the image is pulled in through another post type's data, I'm at a complete loss for how to pull its ACF data as well.

-- ACF to REST API Version 3.1.0 ACF to REST API Recursive 1.0.0 ACF 5.8.3 Wordpress 5.2.2