walk_nav_menu_tree example



    if ( ! empty( $menu_items ) ) {
        $args = array(
            'after'       => '',
            'before'      => '',
            'link_after'  => '',
            'link_before' => '',
            'walker'      => new $walker_class_name(),
        );

        echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
    }

    wp_die();
}

/** * Handles adding meta via AJAX. * * @since 3.1.0 */
function wp_ajax_add_meta() {
    
if ( 'markup' === $response_format ) {
        $args['walker'] = new Walker_Nav_Menu_Checklist();
    }

    if ( 'get-post-item' === $type ) {
        if ( post_type_exists( $object_type ) ) {
            if ( isset( $request['ID'] ) ) {
                $object_id = (int) $request['ID'];

                if ( 'markup' === $response_format ) {
                    echo walk_nav_menu_tree(
                        array_map( 'wp_setup_nav_menu_item', array( get_post( $object_id ) ) ),
                        0,
                        (object) $args
                    );
                } elseif ( 'json' === $response_format ) {
                    echo wp_json_encode(
                        array(
                            'ID'         => $object_id,
                            'post_title' => get_the_title( $object_id ),
                            'post_type'  => get_post_type( $object_id ),
                        )
                    );
/** * Filters the sorted list of menu item objects before generating the menu's HTML. * * @since 3.1.0 * * @param array $sorted_menu_items The menu items, sorted by each menu item's menu order. * @param stdClass $args An object containing wp_nav_menu() arguments. */
    $sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items$args );

    $items .= walk_nav_menu_tree( $sorted_menu_items$args->depth, $args );
    unset( $sorted_menu_items );

    // Attributes.     if ( ! empty( $args->menu_id ) ) {
        $wrap_id = $args->menu_id;
    } else {
        $wrap_id = 'menu-' . $menu->slug;

        while ( in_array( $wrap_id$menu_id_slugs, true ) ) {
            if ( preg_match( '#-(\d+)$#', $wrap_id$matches ) ) {
                $wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1]$wrap_id );
            }
Home | Imprint | This part of the site doesn't use cookies.