Home › Forums › Feature Requests › REST API
Some of you probably already know http://v2.wp-api.org/
The following quote explains the reason why such a plugin was made and what is it for:
WordPress is moving towards becoming a fully-fledged application framework, and we need new APIs. This project was born to create an easy-to-use, easy-to-understand and well-tested framework for creating these APIs, plus creating APIs for core.
It would be great if ACF had REST API as well. At the moment we can only access custom fields via standard post meta. As you know it’s not the most convienient way to get ACF data.
I know it is not a trivial case, but is there any chance to implement such a feature in ACF?
Hi wube,
you can use the plugin ACF to REST API:
GitHub: https://github.com/airesvsg/acf-to-rest-api/
WordPress.org: http://www.wordpress.org/plugins/acf-to-rest-api
Hi Guys
I have installed the ACF to WP REST API plugin but it only seems to work with GET requests, is there a way to use REST API to POST or PUT data into existing ACF fields?
Hi Effigy,
Thanks for using my plugin.
I’ll implement when they published the final version of the plugin WP REST API, it’s still in beta.
https://github.com/airesvsg/acf-to-wp-rest-api/issues/2
Hi Airesvsg,
Is there a timeframe for the final version of WP REST API?
in the meantime, do you know if there is there a work around to get data into ACF fields via the API ?
Cheers
Hi,
It should have a timeframe, but I do not know to inform.
I do not know, I sent an email to Eliot, but was talking about the plugin ( ACF to WP REST API ), I will write another asking about it.
Cheers
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
Hi @hallwrk,
You get some response when you accessing the url below?
http://my-domain/wp-json/acf
Cheers
I get no route 404:
http://gigil.berlin/current/xjazz/wp-json/acf
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…
@hallwrk which directory you installed the plugin?
[404] http://gigil.berlin/current/xjazz/wp-content/plugins/acf-to-wp-rest-api/
@hallwrk you are using another plugin 😀
You can download my plugin on the links below:
https://wordpress.org/plugins/acf-to-wp-rest-api/
or
http://github.com/airesvsg/acf-to-wp-rest-api
Hi @hallwrk,
I saw that isn’t listing yet, try the steps below:
1- Access the permalinks settings ( Settings > Permalinks );
2- Click the Save Changes button.
Hi @airesvsg! Sorry, was offline over the weekend.
The plugin is working wonderfully. I just have it running locally so far.
Thank you!
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 @hallwrk,
you can use filter, see below how to use.
https://github.com/airesvsg/acf-to-wp-rest-api#filter
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'] ) ) {
unset( $data['acf'] );
}
return $data;
}, 10, 3 );
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.
The topic ‘REST API’ is closed to new replies.
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.