Skip to content

Instantly share code, notes, and snippets.

@radames
Created August 8, 2019 18:57
Show Gist options
  • Save radames/a3925b4d5bdaf4eaed21d252df6dfcce to your computer and use it in GitHub Desktop.
Save radames/a3925b4d5bdaf4eaed21d252df6dfcce to your computer and use it in GitHub Desktop.
Simple Register ACF Field to Wordpress REST API / Add this code to functions.php
// 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