Displaying a List of Custom Menus in Custom Meta Box
-
I’m trying to create a custom meta box that has a dropdown select list of all user-created custom menus. I think I’m close but I can’t get the list of menus to “echo” the way I need it to. Here’s what I have so far…
$menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); foreach ( $menus as $menu ) { // this echoes a list of all the menus with a comma behind them... echo $menu->name . ', '; } // Adding sub menu drop down to pages. $meta_boxes[] = array( 'id' => 'sub_menu', 'title' => 'Sub Menu', 'pages' => array('page'), 'context' => 'normal', 'priority' => 'high', 'fields' => array( array( 'name' => 'Select Sub Menu', 'desc' => 'The sub menu for this page created via Appearance > Menus', 'id' => $prefix . 'custom_menu', 'type' => 'select', 'options' => // WHAT WILL WORK HERE??? ) ) );
I’ve tried to save the data in an array and output that in the “options” param but when I var_dump $menus, It’s full of all sorts of data, not just the menu names and thus it throws errors. The format needs to be…
'options' => array('Option 1', 'Option 2', 'Option 3')
I also had no luck with the implode() function since there’s so much extra data in $menus that I don’t need which throws errors.
My lack of skills with arrays is hurting progress. Any thoughts are appreciated.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Displaying a List of Custom Menus in Custom Meta Box’ is closed to new replies.