Created
June 30, 2013 09:58
-
-
Save stugoo/5894584 to your computer and use it in GitHub Desktop.
Encodes advance custom fields for JSON output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires ACF & JSON-API | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment