How do I generate a custom menu/sub-menu system using wp_get_nav_menu_items in WordPress?

To generate a custom menu/sub-menu system using wp_get_nav_menu_items in WordPress, you can follow these steps:

  1. Create a new menu in the WordPress dashboard by going to Appearance > Menus.
  2. Add items to the menu and organize them into sub-menus by using the drag-and-drop interface.
  3. Use the wp_nav_menu function to display the menu in your theme. This function takes an array of arguments, including the menu argument, which should be set to the name or ID of the menu you want to display.
  4. Use the wp_get_nav_menu_items function to retrieve the items in the menu. This function takes the ID of the menu as its only argument.
  5. Loop through the items returned by wp_get_nav_menu_items and use the menu_item_parent property to determine if an item is a parent or child item.
  6. Use the has_children property to check if a menu item has any child items.
  7. Use the title and url properties to output the link and label for each menu item.
  8. Use if and else statement to check if the current menu item is a parent or child and display it accordingly
  9. Use wp_get_nav_menu_items() to get the child items of the parent item if it is a parent.
  10. Repeat the step 7 and 8 for child items as well.

It's also a good idea to customize the output of your menu using CSS to match the design of your website.