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

Recursive with custom post types

Open antoniostarace opened this issue 5 years ago • 5 comments

Hi, I can't make it work as I need and I don't understand if I do it wrong or simply it is not possible.

I have two custom post types: "menus" and "dishes";

Eash dish has a few fields, say "dish name (post title)", "dish price", "dish description";

I want to create dishes and associate them to menus via relationship field.

Example: MENU 1 dish 2, dish 4, dish 7

MENU 2 dish 1, dish 6, dish 11

If i call menu 1 via rest with url .../wp-json/acf/v3/custom_menu/1 I get dish names (which are post titles) but can't get post acf fields.

The same happens if I call .../wp-json/wp/v2/custom_menu/8, slightly different response but no acf fields.

I tried registering post types with Custom Post Types UI, Types, via code, but none of those makes any difference.

Thank you

antoniostarace avatar Mar 14 '19 12:03 antoniostarace

I had the same problem and did the following to make it work:

In library/class-acf-to-rest-api-recursive.php go to line 19 and add your cpts to the $types array. This will add them, so they are handled by the plugin.

$types = array( 'options' => 'options', 'comments' => 'comments', 'users' => 'users', 'custom_menu' => 'custom_menu', 'custom_dish' => 'custom_dish' )

FloLech avatar Apr 29 '19 16:04 FloLech

Seems to be an issue with the after_setup_theme action. It seems to be too early in the lifecycle in which the CPT doesn't get created yet. I changed it to init and set the priority value to 1000 to make sure it is last in the list of init calls. This makes it to where the CPT should be created.

rbaugh avatar Dec 26 '19 20:12 rbaugh

Seems to be an issue with the after_setup_theme action. It seems to be too early in the lifecycle in which the CPT doesn't get created yet. I changed it to init and set the priority value to 1000 to make sure it is last in the list of init calls. This makes it to where the CPT should be created.

Looks like this was identified here as well: https://github.com/joshuafredrickson/acf-to-rest-api-recursive/commit/84f119ead5493425ba3503d7e2204af24c11bbd1

rbaugh avatar Dec 26 '19 20:12 rbaugh

Has anyone solved this problem?

MaximBuldov avatar Nov 09 '21 20:11 MaximBuldov

Seems to be an issue with the after_setup_theme action. It seems to be too early in the lifecycle in which the CPT doesn't get created yet. I changed it to init and set the priority value to 1000 to make sure it is last in the list of init calls. This makes it to where the CPT should be created.

Looks like this was identified here as well: joshuafredrickson@84f119e

Just do this

tariky avatar Nov 21 '23 13:11 tariky