wp_get_nav_menus()
Gets an array (of objects) of all menus from the database.
This is a wrapper for the function get_terms(), which retrieves term data for the taxonomy nav_menu.
Uses: get_terms()
Hooks from the function
Returns
WP_Term[]. An array that contains objects with data about each menu.
Usage
wp_get_nav_menus( $args );
- $args(array)
Array of arguments by which the menus will be retrieved. For the arguments that can be passed, see the function get_terms().
Default parameter value when nothing is set in this parameter:
array( 'taxonomy' => 'nav_menu', 'hide_empty' => false, 'orderby' => 'name' );
Default: array()
Examples
#1 Output Demo
$menus = wp_get_nav_menus( $args ); print_r( $menus ); /* He will: Array ( [0] => stdClass Object ( [term_id] => 3 [name] => menu 1 [slug] => menu-1 [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 1 ) [1] => stdClass Object ( [term_id] => 4 [name] => Menu 2 [slug] => menu-2 [term_group] => 0 [term_taxonomy_id] => 4 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 2 ) ) */
Changelog
| Since 3.0.0 | Introduced. |
| Since 4.1.0 | Default value of the 'orderby' argument was changed from 'none' to 'name'. |
wp_get_nav_menus() wp get nav menus code WP 6.9.1
function wp_get_nav_menus( $args = array() ) {
$defaults = array(
'taxonomy' => 'nav_menu',
'hide_empty' => false,
'orderby' => 'name',
);
$args = wp_parse_args( $args, $defaults );
/**
* Filters the navigation menu objects being returned.
*
* @since 3.0.0
*
* @see get_terms()
*
* @param WP_Term[] $menus An array of menu objects.
* @param array $args An array of arguments used to retrieve menu objects.
*/
return apply_filters( 'wp_get_nav_menus', get_terms( $args ), $args );
}