Expose ACF Fields in the WordPress REST API

Make ACF field data available in WordPress REST API responses for headless and decoupled builds.

php rest-api
|

Make ACF field data available in WordPress REST API responses for headless and decoupled builds.

The simplest approach is to enable “Show in REST API” on your field group settings in the ACF admin. This adds an acf property to REST API responses automatically.

To enable it programmatically for a field group registered via PHP:

<?php
add_action( 'acf/init', function () {
    acf_add_local_field_group( [
        'key'                   => 'group_my_fields',
        'title'                 => 'My Fields',
        'show_in_rest'          => true,
        'fields'                => [ /* ... */ ],
        'location'              => [ /* ... */ ],
    ] );
} );

To manually add ACF fields to a custom post type’s REST response using register_rest_field():

<?php
add_action( 'rest_api_init', function () {
    register_rest_field( 'post', 'acf_fields', [
        'get_callback' => function ( $post ) {
            return get_fields( $post['id'] );
        },
        'schema'       => null,
    ] );
} );

When fetching data, you can scope the response to only include ACF fields:

GET /wp-json/wp/v2/posts?_fields=id,title,acf

To return full objects instead of IDs for relational fields (images, post objects, etc.), append the acf_format parameter:

GET /wp-json/wp/v2/posts/123?acf_format=standard

Related Snippets

Stay Updated

Get ACF tips and new extensions in your inbox

No spam. Unsubscribe anytime.