This is for a JSON API Endpoint (not a web site). Currently I'm getting all custom fields for a post separately via
get_fields($post_id)
Is there any way to get all associated custom fields with the get_post
/ get_posts
functions?
How I'm merging now:
try {
// gather all the posts
$posts = get_posts(array(
'posts_per_page' => 20,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'custom_post',
'post_status' => 'publish'
));
} catch(Exception $e) {
return $this->error($e->getMessage());
}
try {
// merge the acf in with the original post data
for($i = 0; $i < count($posts); ++$i) {
$post = $posts[$i];
$acf = get_fields($post->ID);
$post->acf = $acf;
}
} catch(Exception $e) {
return $this->error($e->getMessage());
}
get_fields()
in The Loop while displaying the post? Also, please note that questions regarding 3rd party plugins ( such as Advanced Custom Fields ) is considered to be off-topic here and may be better suited for their support forums.