0

In order to create a special menu for the splash page of a wordpress site I need access to the elements from the wordpress menu.

At first I thought that it was a simple array but it seems the information is all stored in a string and needs to be parsed.

However I need to retrieve single menu item names and links to be able to place them in my custom menu. (Which is created using

I do not want to hardcode the names and links, this would be really annoying and unprofessional. :( is there any way to access the elements from the wordpress wp_get_nav_menu_items(), store them in an array and access them individually? (I cannot use a foreach() solution.)

  • That function returns an array if memory serves, so this should be no problem? Has this not been answered elsewhere? Look here for example http://stackoverflow.com/questions/11935423/how-do-i-generate-a-custom-menu-sub-menu-system-using-wp-get-nav-menu-items-in-w btw, what do you mean by access individually? Why not loop through the array? – Kalle Jun 24 '15 at 13:28
  • Because on the frontpage I do not need / want all entries - but I want it to be the same menu that is later displayed on the subpages. After some more resarch I guess it all comes down to retrieving individual entries from that array. I can't figure out though how to tell the difference between the tiers when retrieving the info. :( (main / submenu items) – Manfred Wisniewski Jun 24 '15 at 16:51

1 Answers1

0

Even though your link SilverSkin does not give the direct solution to the problem it showed me the right way. Thanks! I used the wp_get_nav_menu_items() function and then exported all the titles and urls to their own array for single access. (for the main menu items) And the submenu items I filter via menu_item_parent and add them to the main menu items via a conditional foreach loop.

The main "trick" (problem) is that the main menu items have no parents and do not have IDs that can be (easily) used for access. So the trick is setting those IDs to the iteration value ($key) when exporting.

if (!$menu_item->menu_item_parent) { $key = $menu_item->ID; }

(for more details check SilverSkins link)