Support

Account

Home Forums Backend Issues (wp-admin) ACF to Rest API Not Working

Solved

ACF to Rest API Not Working

  • Hello,

    I created a script to dynamically create posts and also update the ACF fields via update_field().

    For some reason not all my ACF fields are being pulled when I’m using the ACF to Rest API plugin. I seem to be able to only grab one field.

    as you can see here:
    http://www.oneupsports.com/wp-json/acf/v2/post/1165

    The strange part is if I manually go in and edit the page and just hit the “update” button the field then will show up:
    http://www.oneupsports.com/wp-json/acf/v2/post/1105

    Is there something I can do to either,
    a) make the field show up during the creating post process, or
    b) dynamically update the post so the field shows up.

    I’ve tried using $update_post() function, but it doesn’t add the ACF fields to the rest api.

    Any help will be great.

    Thanks

  • Before a post is created there are no values in the ACF fields and they do not exist yet. The post meta values don’t exist until the first time a post is saved. As far as making the fields show up using the ACF to REST API, you’d probably need to talk to them about it. That is a 3rd party plugin and I think they’d be the best source of information.

    Short of that you’d need to build something into your client side app that populates default values if none of returned for specific fields.

  • Ahh ok, I create a new issue thread on their github, just waiting to hear back.

    Short of that you’d need to build something into your client side app that populates default values if none of returned for specific fields.

    Do you have any suggestion on how to do this? I’m not too familiar with WordPress myself.
    If you can direct me to the right path, that would be great.

    Thanks!

  • I have not used the rest api with acf, but generally, in templates, I do something like

    
    $value = get_field('field-name');
    if (!$value) {
      $value = 'default value';
    }
    

    Since I’m assuming that you’re building code in javascript to use the rest api, you’ll need to alter this to check whatever field your looking for in what the api returns.

    Like I said, the people that put together the acf to rest plugin will likely be able to answer you’re questions better than anyone.

  • Ok Great!

    Thanks man,
    Appreciate it.

  • Hi John and Radizzt,

    I am having the issue where when running the get request the custom fields I created are not showing up in the feed.

    If I’m reading this correctly I need to add the custom fields in the below format to a template or to custom post type theme templates in my theme? Or can I add a it to functions.php?

    Do I do this for every field?

    $value = get_field('field-name');
    if (!$value) {
      $value = 'default value';
    }

    Advanced Custom Fields Pro (Latest V5)

    I’ve added the rest API plugin and that didn’t work.

    Thanks for your help.

  • The code you posted would go in a theme template file where you want to display the field.

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

The topic ‘ACF to Rest API Not Working’ is closed to new replies.