Same problem here,
function albums_endpoint( $request_data ) {
// setup query argument
$args = array(
‘post_type’ => ‘albums’,
‘posts_per_page’=>-1,
‘numberposts’=>-1
);
// get posts
$posts = get_posts($args);
// add custom field data to posts array
foreach ($posts as $key => $post) {
$posts[$key]->acf = get_fields($post->ID);
$posts[$key]->link = get_permalink($post->ID);
$posts[$key]->image = get_the_post_thumbnail_url($post->ID);
$posts[$key]->gallery = acf_photo_gallery(‘ACF_FIELD_NAME’, $post->ID);
}
return $posts;
}
// register the endpoint
add_action( ‘rest_api_init’, function () {
register_rest_route( ‘albums/v1’, ‘/albums/’, array(
‘methods’ => ‘GET’,
‘callback’ => ‘albums_endpoint’,
)
);
});
API return ==
[
{
“ID”: 33,
“post_author”: “1”,
“post_date”: “2019-01-05 18:45:06”,
“post_date_gmt”: “2019-01-05 18:45:06”,
“post_content”: “”,
“post_title”: “The first test album”,
“post_excerpt”: “”,
“post_status”: “publish”,
“comment_status”: “closed”,
“ping_status”: “closed”,
“post_password”: “”,
“post_name”: “brouillon-auto”,
“to_ping”: “”,
“pinged”: “”,
“post_modified”: “2019-01-05 20:39:26”,
“post_modified_gmt”: “2019-01-05 20:39:26”,
“post_content_filtered”: “”,
“post_parent”: 0,
“guid”: “https://gyuto.local/?post_type=albums&p=33”,
“menu_order”: 0,
“post_type”: “albums”,
“post_mime_type”: “”,
“comment_count”: “0”,
“filter”: “raw”,
“acf”: {
“album_title”: “The first test album”
},
“link”: “https://gyuto.local/albums/brouillon-auto/”,
“image”: false,
“gallery”: []
}
]
Can someone help siknoidas (@siknoidas) and I ??
Thanks