Skip to content

Instantly share code, notes, and snippets.

@diegochavez
Created January 5, 2014 09:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diegochavez/8266151 to your computer and use it in GitHub Desktop.
Save diegochavez/8266151 to your computer and use it in GitHub Desktop.
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);
}
@Marko351
Copy link

Marko351 commented Mar 8, 2019

Where can I put this code exactly, if i want that to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment