Thank you for resolving this, I found your answer very useful. However, the syntax you used threw errors when I tried to paste it directly into my site – specifically the quote marks “
and ‘
, it appears they are not valid for PHP. You should use "
and '
instead.
Here is a correctly formatted version:
$post_type = "evento";
function my_rest_prepare_post($data, $post, $request) {
$_data = $data->data;
$_data['acf_photo_gallery'] = acf_photo_gallery('galeria_detalle', $post->ID);
$data->data = $_data;
return $data;
}
add_filter("rest_prepare_{$post_type}", 'my_rest_prepare_post', 10, 3);
Also, for anyone new to WordPress (like me), some tips on where/how to use this would have been great!
The $post_type
variable should be the slug of your post type, and the first argument passed to acf_photo_gallery
should be the name of the acf gallery field you are trying to match. I eventually figured out I could install the Code Snippets plugin and add this as a new snippet. It now works fine.
-
This reply was modified 3 years, 6 months ago by lawrencewitt.