Skip to content

Instantly share code, notes, and snippets.

@rileypaulsen
Created August 19, 2014 16:08
Show Gist options
  • Save rileypaulsen/9b4505cdd0ac88d5ef51 to your computer and use it in GitHub Desktop.
Save rileypaulsen/9b4505cdd0ac88d5ef51 to your computer and use it in GitHub Desktop.
Add Advanced Custom Fields Fields to the WP REST API
function wp_api_encode_acf($data,$post,$context){
$data['meta'] = array_merge($data['meta'],get_fields($post['ID']));
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}
@estebanmunchjones2019
Copy link

great contribution @rileypaulsen! thanks. it works

@gmatta01
Copy link

Thanks @mehmoodak !

@ZeldOcarina
Copy link

Thank you so much @mehmoodak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment