New version: https://github.com/airesvsg/acf-to-rest-api/
Puts ACF data into the WP-REST-API ( WP-API | WordPress JSON API ). Also you can customize the answer using filters.
- Copy the
acf-to-wp-rest-api
folder into yourwp-content/plugins
folder - Activate the
ACF to WP REST API
plugin via the plugins admin page
- /wp-json/acf/post/
<ID>
- /wp-json/acf/page/
<ID>
- /wp-json/acf/user/
<ID>
- /wp-json/acf/term/
<ID>
/<TAXONOMY>
- /wp-json/acf/comment/
<ID>
- /wp-json/acf/attachment/
<ID>
- /wp-json/acf/
options
- /wp-json/acf/options/
<FIELD_NAME>
{
"ID" : 1,
"post_title" : "Post 1",
"..."
"acf" : {
"field1" : "value 1",
"field2" : "value 2"
}
}
Use the filter (acf_to_wp_rest_api_{type}
_data) to customize the answer.
The wildcard {type}
can be: post, page, user, term, comment, attachment or options
add_filter( 'acf_to_wp_rest_api_post_data', function( $data, $object, $context ) {
if ( isset( $data['type'] ) && 'my_post_type' == $data['type'] && isset( $data['acf'] ) ) {
// do something
}
return $data;
}, 10, 3 );