Skip to content

Instantly share code, notes, and snippets.

@devwax
Last active February 25, 2021 04:28
Show Gist options
  • Save devwax/9228f548c94a085b5f8f85ea84a2cbaa to your computer and use it in GitHub Desktop.
Save devwax/9228f548c94a085b5f8f85ea84a2cbaa to your computer and use it in GitHub Desktop.
WP REST API snippets / notes
// Register acf fields to Wordpress API (functions.php)
// 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_page', 'acf_to_rest_api', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment