Home › Forums › Backend Issues (wp-admin) › JSON REST API and ACF?
Is there any way that I can access ACF custom field data with JSON REST API?
I’m building a mobile app and I want to use WordPress to handle registrations and the record keeping. The app will get and put data from the WP database.
Thanks.
Hi,
I would like to see the same functionality here – any hint would help a lot!
Thanks!
The way this got solved for the JSON API plugin was through this…
http://stackoverflow.com/questions/10132685/json-api-to-show-advanced-custom-fields-wordpress
…which uses a hook specific to that plugin. For the WP-API function, it looks like maybe wp_json_server_before_serve
is the thing to hook into?
Figured it out. The correct hook is json_prepare_post
.
<?
add_filter('json_prepare_post', 'json_api_encode_acf');
function json_api_encode_acf($post) {
$acf = get_fields($post['ID']);
if (isset($post)) {
$post['acf'] = $acf;
}
return $post;
}
?>
Quick question. Is this function only for adding ACF data to a GET request?
I am trying to POST data from WP-API to ACF, but I’m struggling to find a way.
Many thanks
Sorry, my solution was only for a GET request. I haven’t tried to use a POST request, but I’m pretty sure there’s an easy way to do it. Have you looked at update_field before?
There was an issue openend in august 14 over at the REST API repo concerning ACF. The short answer is that ACF needs to handle this.
If you just want read ACF fields PanManAms supplied a wordpress plugin in the same thread which will add ACF field values to the REST API.
—Git Hub Issue: https://github.com/WP-API/WP-API/issues/433
—Plugin: https://github.com/PanManAms/WP-JSON-API-ACF
Hi @traipler,
Now you can edit the ACF fields using WordPress REST API.
https://github.com/airesvsg/acf-to-rest-api
@airesvsg What about editing repeater fields? I’m not sure how to target a repeater field.
Hi @keygrip,
Please, check my example:
https://github.com/airesvsg/acf-to-rest-api-example
Live demo
http://airesgoncalves.com.br/acf-to-rest-api/
Jason how do you make it working?
I can’t make it working with acf pro 🙁
(tried with acf free and it worked)
any hints please?
There is a way to update via REST API a Woocommerce product Category acf field?
I saw that in the endpoint list (https://domain.com/2020/wp-json/acf/v3/) … there is not an endpoint for Woocommerce product Categories!!!
but if possible I want to update the acf field by using the Woocommerce endpoint:
https://domain.com/2020/wp-json/wc/v3/products/categories/123
I tried with:
endpoint:
https://domain.com/2020/wp-json/wc/v3/products/categories/123
json string:
{“name”:”My Category”,”slug”:”my-category”,”meta_data”:[{“key”:”my_acffieldname”,”value”:”my value”}]}
this works for woocommerce products but not for woocommerce categories!!
please can you help me?
Hello,
this Live Demo URL is not working now. can you please send me some other example for the Repeater field.
I want to insert new post using WP Rest API and that post is also having some repeater fields value. so how can I add that?
I have tried with below code
‘body’ => array(
‘title’ => $_POST[‘title’],
‘excerpt’ => $_POST[‘excerpt’],
‘status’ => ‘publish’,
‘acf’ => array(
’email_id’ => $_POST[’email’],
‘phone_number’ => $_POST[‘phone’],
‘links’ => array(
‘https://www.facebook.com/’,
‘https://twitter.com/’,
‘https://www.instagram.com/’,
)
)
)
But it is sending error like “acf[links][0] is not of type object.”
The topic ‘JSON REST API and ACF?’ 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.