I have a custom post-types called products that contain a list of products.
I have created a menu called hierarchical menu in wordpress dashboard > appearance > menus as illustrated below:
Electronics
-> Camera
-> Headphones
-> Tv accessories
Computers
-> Monitors
-> Keyboards
-> Mouse
Stationaries
-> Pen
-> Pencil
-> Notebooks
-> Paper
I need to create and display a custom menu using shortcode for eg., If I click on camera it displays a list of posts from Product post type with categories of electronics, camera as a submenu
Electronics
-> Camera
--> list of posts with categoreis Electronics / Camera (dynamic)
I am not sure how to go about creating this. I use below code to generate the menu and display using shortcode. But I have zero clue on how to dynamically show the list of posts based on its parent criteria. Any help / Guidance greatly appreciated would be greatly appreciated.
function custom_hierarchical_menu($atts) {
$menu_html = wp_nav_menu( array(
'menu' => 'Hierarchy Desktop Menu',
'echo' => false, // Set 'echo' to false to store the HTML in $menu_html
) );
}
add_shortcode('customHierarchicalMenu', 'custom_hierarchical_menu');