Support

Account

Home Forums Backend Issues (wp-admin) JSON REST API and ACF?

Solving

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.

    • webline

    • August 11, 2014 at 1:09 am

    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?

    • nonement

    • September 9, 2014 at 11:05 pm

    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

  • Please how to EDIT / CREATE also ACF fields using wp-rest-api??

  • How can i create/edit posts?

    Florian

  • Hi @traipler,

    Now you can edit the ACF fields using WordPress REST API.

    https://github.com/airesvsg/acf-to-rest-api

  • This reply has been marked as private.
    • Jason

    • January 26, 2016 at 3:26 am

    @airesvsg What about editing repeater fields? I’m not sure how to target a repeater field.

    • Jason

    • February 12, 2016 at 6:12 am

    Thanks, @airesvsg, I got everything working.

  • 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?

  • Ok i Did it!
    thank you for the great plugins!

    • newtom

    • March 9, 2017 at 10:57 pm
    This reply has been marked as private.
    • pablito

    • December 1, 2020 at 7:18 pm

    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?

Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.