Last active
March 9, 2017 12:17
-
-
Save thsneumann/cff5711dffccbb6c7b62be2594d4bb3d to your computer and use it in GitHub Desktop.
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
<?php | |
/*** Add Advanced Custom Fields to REST API GET Response ***/ | |
/*** tested in WP4.7.3 with ACF4.4.11 | |
/*** https://support.advancedcustomfields.com/forums/topic/json-rest-api-and-acf/ ***/ | |
add_filter('rest_prepare_post', 'rest_api_encode_acf', 10, 3); | |
function rest_api_encode_acf($response, $post, $request) { | |
if (!function_exists('get_fields')) return $response; | |
if (isset($post)) { | |
$acf = get_fields($post->id); | |
$response->data['acf'] = $acf; | |
} | |
return $response; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment