on-internet
← Community

How do I fetch ACF custom fields via REST API in a custom WordPress theme?

Stack Overflow ·

I am building a custom WordPress theme and using Advanced Custom Fields (ACF) to manage dynamic content. I want to fetch and display ACF fields via the REST API, but I’m not getting the expected data in my API response. add_action('rest_api_init', function() { register_rest_field('post', 'my_custom_field', array( 'get_callback' => function($post_arr) { return get_field('my_custom_field', $post_arr['id']); }, 'schema' => null, )); }); I expected the API to return the value of my_custom_field for each post, but the field is either missing or empty in the API response. WordPress version: 6.x ACF

Comments

Sign in or sign up to comment and upvote.

No comments yet.