thebatclaudio / wp-rest-api-v2-menus

Adding menus endpoints on WP REST API v2
47 stars 23 forks source link

More than 2 level of children #16

Closed metawise closed 5 years ago

metawise commented 5 years ago

The plugin not supporting more than 2 levels of menus.

marcel-silva commented 5 years ago

I was able to achieve that by editing the code a bit.

The "wp_api_v2_menus_get_menu_items' function to be more specific.

See image: image

metawise commented 5 years ago

Awesome! I will try that. I was able to achieve with the different plugin but this one seems later version.

thebatclaudio commented 5 years ago

Hi, I resolved the issue implementing a new function to check menu item's relatives. I will release a new version of the plugin ASAP.

josias-r commented 5 years ago

I was able to achieve that by editing the code a bit.

The "wp_api_v2_menus_get_menu_items' function to be more specific.

See image: image

Replace the line unset($menu_items[$key2]) with array_splice($menu_items, $key2, 1). Otherwise the array won't start at an index of 0, which will cause a problem when fetching it as JSON, because JSON converts arrays into objects when the index doesn't start with 0. (Which caused the problem for me that I couldn't use array.map() inside a React application)

Reference: Stackoverflow

@thebatclaudio

thebatclaudio commented 5 years ago

Hi @josias-r, thank you for your advice. I will fix it ASAP.

thebatclaudio commented 5 years ago

I created another issue (#18)