acf-to-rest-api icon indicating copy to clipboard operation
acf-to-rest-api copied to clipboard

Unable to hide field from REST API

Open kvf420 opened this issue 4 years ago • 5 comments

I have this filter enabled in functions.php:

add_filter( 'acf/rest_api/field_settings/show_in_rest', '__return_true' );

The toggle Show in REST API? is visible in field settings but set to No by default. Despite that, all fields are still included in the API. Turning it on and back off does not remove them either.

This issue occurs on options page only, works as expected in other locations (posts, pages, etc.).

WordPress v5.5.1 Advanced Custom Fields PRO v5.9.1 ACF to REST API v3.3.1, Request Version v3

kvf420 avatar Oct 07 '20 21:10 kvf420

We are also experiencing the same issue, the options page ingores these settings.

mzmijana avatar Oct 19 '20 08:10 mzmijana

Could be php caching? I wasn't seeing any change after editing my functions.php page. Took me a while to work out that you have to restart php after each edit if you have php opcache turned on. Doh!!

robtoll avatar Jan 07 '21 12:01 robtoll

Same pb

djoo avatar Jul 15 '21 19:07 djoo

If the options page has id 'options' the call to acf_get_field_groups in line 135 in class-acf-to-rest-act-api.php returns empty.

I made this fix in the same file line 131: if ($id == 'options') { $fields_tmp = get_field_objects( $id ); } elseif ....

I have only tested with one field group on the option page. It there are more, I dont know if it will work.

johannesdb avatar Sep 15 '21 14:09 johannesdb

Yep, same -- I've applied a workaround similar to @johannesdb solution but unsure if it's a robust fix..

grex22 avatar Mar 29 '23 15:03 grex22