Closed warudin closed 4 years ago
{type}
is a placeholder for your own post types. You must also enter the post types you use there.
add_filter('acf/rest_api/my_post_type/get_fields', 'get_featured_image_of_post_object', 10, 2);
Hi @pixelbart
So should I add a separate filter for every post-type? Or is there a way to do it for all post-types at once?
@warudin
You can also simply create an array of your post types and let them pass through the filter.
$post_types = [ 'post_type_1', 'post_type_2', 'post_type_3' ];
foreach ( $post_types as $post_type ) {
add_filter( 'acf/rest_api/' . $post_type . '/get_fields', 'get_featured_image_of_post_object', 10, 2 );
}
In WordPress there is also a function with which you can control all post types:
https://developer.wordpress.org/reference/functions/get_post_types/
I want to add the featured image to the REST output of a post_object, because it's not included by default. So I created the following function
If I use the function with the following hook, it's working fine (for posts):
But I read that it should work for all different endpoints by using {type} as well:
However, for me it doesn't. The added featured_media is not showing up any more. Is my assumption that this should be working wrong?
These are the details of my setup: