Skip to content

Instantly share code, notes, and snippets.

@jacobwise
Last active November 1, 2017 13:11
Show Gist options
  • Save jacobwise/82f034004dfa26c7ef30 to your computer and use it in GitHub Desktop.
Save jacobwise/82f034004dfa26c7ef30 to your computer and use it in GitHub Desktop.
How to add Advance Custom Fields to the JSON API in WordPress.
<?php
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);
}
@ahmedalmulki
Copy link

Hi ,
I add image field to my category by using ACF plugin , how can I access to it through WP REST API V2 plugin ?

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