airesvsg / acf-to-rest-api

Exposes Advanced Custom Fields Endpoints in the WordPress REST API
https://wordpress.org/plugins/acf-to-rest-api/
1.33k stars 111 forks source link

Issue with ACF 5.12 #398

Closed n-kort closed 2 years ago

n-kort commented 2 years ago

Custom fields content isn't showing in rest endpoints any more, it's just an empty array.

danman335 commented 2 years ago

Yep seeing that here also.

thrugl commented 2 years ago

Me three

jack-pallot commented 2 years ago

I'm having a difficult time replicating this, to the point I can't submit a PR, but I believe the fix is the following:

add_action( 'rest_api_init', array( __CLASS__, 'create_rest_routes' ), 10 );

needs to be changed to:

add_action( 'rest_pre_dispatch', array( __CLASS__, 'create_rest_routes' ), 10 );

In class-acf-to-rest-api.php

willers-pm commented 2 years ago

Try setting "Show in REST API" to true for the field-group(s) in ACF Field Group editor. I think the setting is rather new.

n-kort commented 2 years ago

@willers-pm that causes other errors in my case, but while testing some months back I noticed the schema is different anyway, so held off using the native acf rest support.

@jack-pallot yes changing rest_api_init to rest_pre_dispatch does fix it 🎉 That change also seems to work with ACF 5.11.4

willers-pm commented 2 years ago

@n-kort @jack-pallot changing rest_api_init to rest_pre_dispatch does fix it for me, too. Even for the "relationship"-field where activating the setting in ACF would not fix it. So thanks! :)

jack-pallot commented 2 years ago

I'm happy to submit a PR since this seems to be working. I'm guessing it should probably just target ACF 5.12 and above to avoid breaking any older code.