Home › Forums › Feature Requests › Native ACF JSON API › Reply To: Native ACF JSON API
Hi @sirjonathan
Looks like the simplest answer was hooking in and adding the custom fields like so:
add_filter('json_api_encode', 'json_api_encode_acf');
function json_api_encode_acf($response)
{
if (isset($response['posts'])) {
foreach ($response['posts'] as $post) {
json_api_add_acf($post); // Add specs to each post
}
}
else if (isset($response['post'])) {
json_api_add_acf($response['post']); // Add a specs property
}
return $response;
}
function json_api_add_acf(&$post)
{
$post->acf = get_fields($post->id);
}
http://wordpress.org/extend/plugins/json-api/other_notes/#Filter:-json_api_encode http://stackoverflow.com/questions/10132685/json-api-to-show-advanced-custom-fields-wordpress
The code is so small that I could not charge for it. Maybe you could package it up into a WP plugin?
Thanks
E
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.