Conversation
supportHi, great plugin. I’m at a loss on how to implement the filter hook to format children menu items. I’ve built an example but am unable to parse the children differently. I understand this is the correct filter hook. json_menus_format_menu_item I’m a JSON noob – any direction or examples on how to achieve this would be greatly appreciated. Thanks https://wordpress.org/plugins/wp-api-menus/
Hello Batmanian, if you create a filter for that hook, you can pass as the argument the data to filter example: add_filter( 'json_menus_format_menu_item', 'my_menu_filter', 1 ); function my_menu_filter( $menu_data ) { var_dump($menu_data); // do something with $menu_data return $menu_data; } $menu_data is an array that contains the information that will be fed to WP API – if you want to manipulate this data you can do it in your custom filter callback – you need to make sure that $menu_data is a valid PHP array, it will be encoded to JSON by WP API I’m not sure how you are retrieving the JSON data but if you have put a filter in place, it will be formatted the way you want and the data will be returned at the routes provided by the plugin – the output of course is a JSON object: you can treat a JSON object like a Javascript object and use the data in each of its nodes accordingly – strings, arrays, numbers, bool…
Hi, Thanks for the insight. I’ll do some reading on filters and get to work.
Hi, Great plugin, can easily get all menus and their locations. But I can’t create new menu or edit the existing. I have try to post url..wp-json/wp-api-menus/v2/menus but it doesn’t create new one. What I am doing wrong?
@goharika , the plugin doesn’t create new menu items, you have to use WordPress default menus functions and interface to do that: https://codex.wordpress.org/WordPress_Menu_User_Guide
@goharika , this plugin doesn’t create new menu items, you have to use WordPress default menus functions and interface to do that: https://codex.wordpress.org/WordPress_Menu_User_Guide once that is done, the menu and their elements will be available to the rest api with this plugin
yes I know, but I need to create new one from my application, so I need to post
sorry then, currently it’s in read mode only https://github.com/nekojira/wp-api-menus/blob/master/lib/wp-api-menus-v2.php#L47 to do other CRUD operations the plugin needs to be expanded further
Hello Batmanian, if you create a filter for that hook, you can pass as the argument the data to filter example: add_filter( 'json_menus_format_menu_item', 'my_menu_filter', 1 ); function my_menu_filter( $menu_data ) { var_dump($menu_data); // do something with $menu_data return $menu_data; } $menu_data is an array that contains the information that will be fed to WP API – if you want to manipulate this data you can do it in your custom filter callback – you need to make sure that $menu_data is a valid PHP array, it will be encoded to JSON by WP API I’m not sure how you are retrieving the JSON data but if you have put a filter in place, it will be formatted the way you want and the data will be returned at the routes provided by the plugin – the output of course is a JSON object: you can treat a JSON object like a Javascript object and use the data in each of its nodes accordingly – strings, arrays, numbers, bool…
Hi, Thanks for the insight. I’ll do some reading on filters and get to work.
Hi, Great plugin, can easily get all menus and their locations. But I can’t create new menu or edit the existing. I have try to post url..wp-json/wp-api-menus/v2/menus but it doesn’t create new one. What I am doing wrong?
@goharika , the plugin doesn’t create new menu items, you have to use WordPress default menus functions and interface to do that: https://codex.wordpress.org/WordPress_Menu_User_Guide
@goharika , this plugin doesn’t create new menu items, you have to use WordPress default menus functions and interface to do that: https://codex.wordpress.org/WordPress_Menu_User_Guide once that is done, the menu and their elements will be available to the rest api with this plugin
yes I know, but I need to create new one from my application, so I need to post
sorry then, currently it’s in read mode only https://github.com/nekojira/wp-api-menus/blob/master/lib/wp-api-menus-v2.php#L47 to do other CRUD operations the plugin needs to be expanded further