Why is my array of nav menus returning empty?

I am trying to retrieve of list of available menus but the array is returning empty.

function get_menus() {
    $menu_list = [];
    $wcs_menus = wp_get_nav_menus();
    foreach($wcs_menus as $m) {
        $menus_list[$m->slug] = $m->name;
      }
      return $menu_list;
}

$menus = get_menus();
var_dump($menus);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Are you missing a “s” in your variable return $menu_list;?
Your array is called $menus_list;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x