airesvsg / acf-to-rest-api-recursive

Get ACF fields recursively
43 stars 8 forks source link

Recursive with custom post types #6

Open antoniostarace opened 5 years ago

antoniostarace commented 5 years ago

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

FloLech commented 5 years ago

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' )

rbaugh commented 4 years ago

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 commented 4 years ago

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

MaximBuldov commented 3 years ago

Has anyone solved this problem?

tariky commented 11 months ago

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