Thanks! I was looking at that, and then when I updated the WP REST API to Version 2.0-beta9, it broke your plugin. Looks like they changed the structure in the last release slightly. I’m looking forward to the release version of the API and will revisit your plugin when it is ready, but for now I think I’ll have to stick to the method in the WP REST API documentation to reduce version dependency.
Just a small update on this.
I ended up not using a plugin at all, but instead just adding the ACF fields by batch like this:
add_action( 'rest_api_init', 'slug_register_acf' );
function slug_register_acf() {
$post_types = get_post_types(['public'=>true], 'names');
foreach ($post_types as $type) {
register_api_field( $type,
'acf',
array(
'get_callback' => 'slug_get_acf',
'update_callback' => null,
'schema' => null,
)
);
}
}
function slug_get_acf( $object, $field_name, $request ) {
return get_fields($object[ 'id' ]);
}
This appends a key called “acf” to the rest api output for all public post types.
Will be easier to customise too if you only want certain fields to be exposed.
Hi @airesvsg! Sorry, was offline over the weekend.
The plugin is working wonderfully. I just have it running locally so far.
Thank you!
Haha, omg. Thanks… It will probably work now then 🙂
That was the name of the extracted folder. Could that be it?
Thank you for looking into it. Much appreciated!
Could it be related to mod rewrite? Currently, permalinks are set to /%category%/%postname%
But it’s funny that the rest of the api works fine in that case…
I get no route 404:
http://gigil.berlin/current/xjazz/wp-json/acf
Hi, I’m very eager to use ACF pro with wp-api. I’m currently trying to get it set up using @airesvsg ‘s plugin; ACF to WP REST API, however it doesn’t seem to work with the development versions of wordpress, nor version 4.4. I don’t see the ‘acf’ key on the json output at all after trying a lot of various things(disabling, re-enabling, re-installing, enabling options page, deleting posts and custom fields and setting up again etc.)
Would be very awesome if this became a part of ACF pro in the near future, as I’m eager to use it on four current projects.
@airesvsg Would it be possible to get some quick pointers on what the issue might be with my setup? Is it the wp version, or have I missed something?
Thanks for awesome plugins!
h
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.