wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_get_nav_menu_items › WordPress Function
Seit3.0.0
Veraltetn/v
› wp_get_nav_menu_items ( $menu, $args = array() )
Parameter: (2) |
|
Gibt zurück: |
|
Definiert in: |
|
Codex: |
Retrieves all menu items of a navigation menu.
Note: Most arguments passed to the$args
parameter – save for 'output_key' – are
specifically for retrieving nav_menu_item posts from get_posts() and may only
indirectly affect the ultimate ordering and content of the resulting nav menu
items that get returned from this function.Ähnliche Funktionen: wp_save_nav_menu_items, wp_setup_nav_menu_item, wp_get_nav_menus, wp_get_nav_menu_name, _sort_nav_menu_items
Quellcode
function wp_get_nav_menu_items( $menu, $args = array() ) { $menu = wp_get_nav_menu_object( $menu ); if ( ! $menu ) { return false; } if ( ! taxonomy_exists( 'nav_menu' ) ) { return false; } $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_menu_item_cache' => true, 'tax_query' => array( array( 'taxonomy' => 'nav_menu', 'field' => 'term_taxonomy_id', 'terms' => $menu->term_taxonomy_id, ), ), ); $args = wp_parse_args( $args, $defaults ); if ( $menu->count > 0 ) { $items = get_posts( $args ); } else { $items = array(); } $items = array_map( 'wp_setup_nav_menu_item', $items ); if ( ! is_admin() ) { // Remove invalid items only on front end. $items = array_filter( $items, '_is_valid_nav_menu_item' ); } if ( ARRAY_A === $args['output'] ) { $items = wp_list_sort( $items, array( $args['output_key'] => 'ASC', ) ); $i = 1; foreach ( $items as $k => $item ) { $items[ $k ]->{$args['output_key']} = $i++; } } /** * Filters the navigation menu items being returned. * * @since 3.0.0 * * @param array $items An array of menu item post objects. * @param object $menu The menu object. * @param array $args An array of arguments used to retrieve menu item objects. */ return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); }