Created
January 17, 2022 09:03
-
-
Save bepatrickdavid/475f5cbcdedd517338b309273b43caba to your computer and use it in GitHub Desktop.
Add ACF to WP REST API
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
// add this to functions.php | |
//register acf fields to Wordpress API | |
//https://support.advancedcustomfields.com/forums/topic/json-rest-api-and-acf/ | |
function acf_to_rest_api($response, $post, $request) { | |
if (!function_exists('get_fields')) return $response; | |
if (isset($post)) { | |
$acf = get_fields($post->id); | |
$response->data['acf'] = $acf; | |
} | |
return $response; | |
} | |
add_filter('rest_prepare_post', 'acf_to_rest_api', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment