2

I am trying to return an object with values in the category but ACF only returns an array of keys.

Help?

Example of return value & settings

3
  • Why do you have "show in REST API" turned off? Commented May 25, 2022 at 8:25
  • That's the setting for ACF. I used another plugin ( REST API Helper by JasmanXcrew ) to get the REST api working. I ended up creating my own REST Route in WordPress to solve this issue. Not sure why it only returns the keys though, it should return an object of values... Commented May 25, 2022 at 23:12
  • By the way, I have also tried to use the default show in REST Api as well and it returns an array of keys. Commented May 25, 2022 at 23:23

1 Answer 1

4

ACF doesn't respect the "Return Value" selection of the field in REST API responses by default, but if you add the acf_format=standard query param to your request it then respects the return value option.

/wp-json/wp/v2/post?acf_format=standard

https://www.advancedcustomfields.com/resources/wp-rest-api-integration/#controlling-output-format

"Additionally, if you want to default the format to standard for all response data, you can enforce this by using the acf/settings/rest_api_format filter:"

add_filter( 'acf/settings/rest_api_format', function () {
    return 'standard';
} );
Sign up to request clarification or add additional context in comments.

1 Comment

Sooo you're telling me my life has been a lie? For years I've been leveraging custom endpoints to get around this..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.