Setting up a wordpress custom post type rest api acf integration often fails silently: your endpoint returns a 404, or the post appears without any of its custom fields. In WordPress 6.x and modern ACF, you do not need third-party REST bridge plugins to fix this. By configuring show_in_rest on your post type, toggling ACF's native REST setting, and using register_rest_field for edge cases, you will have a clean, predictable JSON payload.
Quick answer
- Set
'show_in_rest' => trueand a clear'rest_base'insideregister_post_type(). - Open your ACF Field Group, go to Settings > Group Settings, and toggle Show in REST API to On.
- Your fields now appear under the
acfkey in/wp-json/wp/v2/{rest_base}. - Use
register_rest_field()only when you need custom formatting, computed values, or strict capability checks. - Flush rewrite rules or visit Settings > Permalinks if the new endpoint returns a 404.
Why your custom post type and ACF fields are missing from REST
When a headless front end or external integration queries /wp-json/wp/v2/your-cpt and gets nothing back, the cause is almost always one of three things. First, register_post_type() defaults show_in_rest to false, which hides the post type from the REST API entirely. Second, ACF hides all field groups from the REST API by default for security reasons, even if the post type itself is exposed.
Third, developers sometimes register a custom post type without custom-fields in its supports array. While ACF's native REST integration reads from the field group configuration, other meta-based tools and register_meta() require custom-fields support to be active. On production builds I start by verifying the post type endpoint first, then checking the acf key, rather than debugging both at once.
Step 1: Expose the custom post type with show_in_rest
To make your post type available in the REST API, show_in_rest must be true in your register_post_type() arguments. You should also set rest_base explicitly so the URL slug matches your API contract, even if you later change the public rewrite slug.
<?php
add_action( 'init', function () {
$args = array(
'label' => __( 'Case Studies', 'textdomain' ),
'public' => true,
'show_in_rest' => true,
'rest_base' => 'case-studies',
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
'rewrite' => array( 'slug' => 'case-studies' ),
);
register_post_type( 'case_study', $args );
} );
This registers the post type case_study and exposes it at /wp-json/wp/v2/case-studies. Including custom-fields in supports ensures standard meta endpoints and Gutenberg compatibility work as expected. If you registered the post type using a UI plugin instead of code, look for the Show in REST API toggle in that plugin's settings.
Verify the endpoint with WP-CLI or curl
Before touching ACF, confirm the post type endpoint responds with a 200 OK status. You can test this from your terminal with curl.
curl -s https://example.com/wp-json/wp/v2/case-studies | head -c 300
If you see a rest_no_route 404 error, your rewrite rules may be stale or show_in_rest is still false. Run wp rewrite flush via WP-CLI or save Settings > Permalinks in the WordPress admin.
Step 2: Enable ACF's native REST API setting
Since ACF 5.11, Advanced Custom Fields includes built-in REST API support. You should not install legacy plugins like "ACF to REST API", which are unmaintained and add unnecessary overhead.
- Open ACF > Field Groups in the WordPress admin and edit the group attached to your custom post type.
- Scroll down to the Settings meta box and click the Group Settings tab.
- Toggle Show in REST API to On.
- Save the field group.
Once enabled, WordPress automatically appends an acf object to each post in /wp-json/wp/v2/case-studies. Every field in that group appears as a key-value pair inside acf, formatted according to your field settings (for example, returning an Image Array vs. an Image ID).
Gotcha: Enabling Show in REST API on an ACF field group exposes every field in that group to unauthenticated GET requests. Never mix public display fields and private internal fields (like admin notes or API keys) in the same field group.
Registering ACF fields via PHP? Set show_in_rest there too
If you export your ACF field groups to PHP or JSON for version control, make sure show_in_rest is set to 1 (or true) in the group array. Otherwise, syncing or loading the PHP registration will overwrite your admin toggle.
<?php
if ( function_exists( 'acf_add_local_field_group' ) ) {
acf_add_local_field_group( array(
'key' => 'group_case_study_details',
'title' => 'Case Study Details',
'fields' => array(
array(
'key' => 'field_client_industry',
'label' => 'Client Industry',
'name' => 'client_industry',
'type' => 'text',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'case_study',
),
),
),
'show_in_rest' => 1,
) );
}
This keeps your REST configuration in Git alongside your theme or plugin code. Whenever you deploy to staging or production, the acf key will be available immediately.
Step 3: When to use register_rest_field instead of ACF's toggle
ACF's native REST output is enough for 90% of headless and decoupled builds. However, there are three situations where register_rest_field() is the better engineering choice:
- You need a computed or combined value: For example, combining two ACF fields into a single formatted string or calculating a reading time.
- You want to reshape relational data: ACF relationship or post object fields return IDs or full post objects, which can bloat your JSON payload. With
register_rest_field(), you can return only theid,title, andslug. - You need custom write (
POST/PATCH) logic: You want strict sanitization and capability checks before updating a field via the REST API.
Here is how to expose a clean, lightweight summary of an ACF relationship field using register_rest_field().
<?php
add_action( 'rest_api_init', function () {
register_rest_field( 'case_study', 'related_services', array(
'get_callback' => function ( $post_arr ) {
$services = get_field( 'related_services', $post_arr['id'] );
if ( empty( $services ) || ! is_array( $services ) ) {
return array();
}
return array_map( function ( $service ) {
return array(
'id' => (int) $service->ID,
'title' => sanitize_text_field( $service->post_title ),
'slug' => sanitize_title( $service->post_name ),
);
}, $services );
},
'schema' => array(
'description' => __( 'Related services summary', 'textdomain' ),
'type' => 'array',
),
) );
} );
This adds a top-level related_services key to the REST response containing only the fields your front end actually needs. Note that register_rest_field() accepts the post type slug (case_study), not the rest_base (case-studies).
Handling permissions and writing ACF fields over REST
By default, ACF's REST API integration respects WordPress post capabilities for POST, PUT, and PATCH requests. An unauthenticated user can read public posts, but cannot modify acf fields unless they are authenticated with a user who has edit_post permissions for that item.
If you are building a custom update_callback with register_rest_field(), always sanitize incoming values and verify capabilities explicitly. Never trust raw JSON input from a request body.
<?php
add_action( 'rest_api_init', function () {
register_rest_field( 'case_study', 'client_industry', array(
'get_callback' => function ( $post_arr ) {
return sanitize_text_field( (string) get_field( 'client_industry', $post_arr['id'] ) );
},
'update_callback' => function ( $value, $post_obj ) {
if ( ! current_user_can( 'edit_post', $post_obj->ID ) ) {
return new WP_Error(
'rest_forbidden',
__( 'You cannot edit this post.', 'textdomain' ),
array( 'status' => 403 )
);
}
update_field( 'client_industry', sanitize_text_field( $value ), $post_obj->ID );
return true;
},
) );
} );
Using current_user_can( 'edit_post', $post_obj->ID ) ensures that only authorized users can update the field, and sanitize_text_field() strips unwanted markup before saving.
Consuming the endpoint in Next.js (App Router)
Once your wordpress custom post type rest api acf setup is returning clean JSON, fetching it in a Next.js App Router Server Component is straightforward. Keep your TypeScript types aligned with the acf object so you catch missing fields at build time.
interface CaseStudy {
id: number;
slug: string;
title: { rendered: string };
acf: {
client_industry: string;
};
}
export async function getCaseStudies(): Promise<CaseStudy[]> {
const res = await fetch(
`${process.env.WP_API_URL}/wp-json/wp/v2/case-studies?_fields=id,slug,title,acf`,
{ next: { revalidate: 300 } }
);
if (!res.ok) {
throw new Error('Failed to fetch case studies');
}
return res.json();
}
Notice the _fields=id,slug,title,acf query parameter. Passing _fields tells WordPress to skip rendering unused keys like content, excerpt, and _links, which keeps your payload small and your Next.js data cache lean.
Checklist
- Set
show_in_rest => trueand an explicitrest_baseinregister_post_type(). - Include
custom-fieldsin the post typesupportsarray. - Flush rewrite rules if
/wp-json/wp/v2/{rest_base}returns a 404. - Enable Show in REST API on each public ACF field group (and in PHP/JSON exports).
- Separate private or internal ACF fields into their own field group with REST disabled.
- Use
register_rest_field()only for computed values, trimmed relationships, or custom write callbacks. - Pass
_fields=on front-endfetchcalls to avoid over-fetching unused post data.
Frequently asked questions
Why are my ACF fields not showing in the WordPress REST API?
ACF hides all field groups from the REST API by default. Edit your field group in the WordPress admin, open the Settings meta box, click Group Settings, and toggle Show in REST API to On. Also confirm your custom post type has show_in_rest set to true.
Do I need the ACF to REST API plugin in WordPress 6.x?
No. Since ACF 5.11, Advanced Custom Fields includes native REST API support out of the box. Third-party bridge plugins like ACF to REST API are no longer needed and add unnecessary maintenance risk. Enable Show in REST API directly on your field group instead.
How do I filter REST API responses by an ACF field value?
WordPress does not allow arbitrary meta_key queries on public REST endpoints by default for performance and security reasons. To filter by an ACF field, hook into rest_{post_type}_query in PHP, validate the query parameter, and map it safely to a meta_query array.
What is the difference between show_in_rest and register_rest_field?
Setting show_in_rest to true on a post type or ACF field group exposes the standard WordPress and ACF data automatically. register_rest_field is a PHP function used to add custom top-level keys, computed values, or trimmed relational data with custom get and update callbacks.
- WordPress Developer ResourcesWordPress Developer Resources
- WordPress REST API HandbookWordPress REST API Handbook
- ACF documentationACF documentation
Drafted with AI assistance. Code targets current WordPress, WooCommerce and Next.js APIs; test changes on a staging site before production.