I am trying to create a REST api get to fetch projects and return them as JSON. I am trying to create a new endpoint, where I am trying to fetch the CPT and the other Advanced Custom Fields.
So far I can retrieve all posts from my custom post type but I would like to get the ACF (fields) as well.
function ldl_get_projects( $data ) {
$posts = get_posts([
'post_type' => 'maps_projects',
'post_status' => 'publish',
'posts_per_page' => -1,
]);
if (empty( $posts ) ) {
return null;
}
$data = [];
foreach ($posts as $post) {
$api_content = [
'name' => $post->post_title,
'description' // ACF
'cargo' => // ACF
'services' => // ACF
'origin' => // ACF
'destination' => // ACF
'specifics' => // ACF
'long' => // ACF
'lat' => // ACF
'gallery' => // ACF
];
$data[] = $api_content;
}
return $data;
}
As you can see, the fields marked with // ACF need to fetch the ACF field. Can someone assist me a little further with this?
Thanks.