Created
August 19, 2014 16:08
-
-
Save rileypaulsen/9b4505cdd0ac88d5ef51 to your computer and use it in GitHub Desktop.
Add Advanced Custom Fields Fields to the 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
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); | |
} |
@albertoavv The REST route you are giving isn't correct. I didn't work with ACF REST API so please read their docs carefully. By the way I also thinks that in your path wp/wp5/wp-json
should be changed to wp/wp-json
Thank you for your response, if what happens is that w5 is the name of the project or the root, but thanks for your response I will continue looking for a solution,
Regards
@mehmoodak thnx for your solution. Do you have any suggestion to specify only which ACF fields do you want to retrieve or not ?
great contribution @rileypaulsen! thanks. it works
Thanks @mehmoodak !
Thank you so much @mehmoodak !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mehmoodak: Thank you :)