WordPress at a glance

wp_get_nav_menu_object() WP 1.0

Returns a navigation menu object.

Is the basis for: wp_get_nav_menu_items()
Works based on: get_term(), get_term_by()
✈ 1 time = 0.000026s = very fast | 50000 times = 0.24s = very fast

No Hooks.

Return

WP_Term/false. False if $menu param isn't supplied or term does not exist, menu object if successful.

Usage

wp_get_nav_menu_object( $menu );
$menu(int/string/WP_Term) (required)
Menu ID, slug, name, or object.

Code of wp_get_nav_menu_object: wp-includes/nav-menu.php VER 5.0.1

<?php
function wp_get_nav_menu_object( $menu ) {
	$menu_obj = false;

	if ( is_object( $menu ) ) {
		$menu_obj = $menu;
	}

	if ( $menu && ! $menu_obj ) {
		$menu_obj = get_term( $menu, 'nav_menu' );

		if ( ! $menu_obj ) {
			$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
		}

		if ( ! $menu_obj ) {
			$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
		}
	}

	if ( ! $menu_obj || is_wp_error( $menu_obj ) ) {
		$menu_obj = false;
	}

	/**
	 * Filters the nav_menu term retrieved for wp_get_nav_menu_object().
	 *
	 * @since 4.3.0
	 *
	 * @param WP_Term|false      $menu_obj Term from nav_menu taxonomy, or false if nothing had been found.
	 * @param int|string|WP_Term $menu     The menu ID, slug, name, or object passed to wp_get_nav_menu_object().
	 */
	return apply_filters( 'wp_get_nav_menu_object', $menu_obj, $menu );
}

Related Functions

From tag: nav menu (nav_menu)

More from category: Menu

No comments
    Hello, !     Log In . Register