Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Pre WordPress 3.x I was using:


add_action( 'init', 'product_register' );
add_filter( 'wp_page_menu', 'custom_page_nav', 90 );

function product_register()
{
    //    register_post_type( 'product', $args );

    register_taxonomy( "catalog", array( "product" ), array( "hierarchical" => true, "label" => "Catalogs",
        "singular_label" => "Catalog", 'hierarchical' => true, 'show_ui' => true, 'show_in_nav_menus' => true,
        'show_tagcloud' => true, 'query_var' => true, "rewrite" => true, 'public' => true, 'capability_type' => 'post' ) );
    //'_builtin' => false,'_edit_link' => 'post.php?post=%d',
    ////////////////////////////////////////////////

}

function custom_page_nav( $menu )
{
    $taxonomy = 'catalog';
    $orderby = 'name';
    $show_count = 0; // 1 for yes, 0 for no
    $pad_counts = 1; // 1 for yes, 0 for no
    $hierarchical = true; // 1 for yes, 0 for no
    $title = '';

    $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts,
        'hierarchical' => $hierarchical, 'title_li' => false, 'echo' => false, 'empty' => true, 'hide_empty' => true,
        'depth' => 0 );
    $links .= wp_list_categories( $args );
    //  $links .= wp_list_categories( array( 'title_li' => false, 'echo' => false, 'empty' => true ) );
    $menu = str_replace( '', 'Prodcuts ' . $links . '', $menu );
    //
    return $menu;
}

How do I do the same thing with the New WordPress 3.x menus.
Using another post on here I was able to figure out how to make a new menu but not add the custom taxonomy items to it:


function register_typenav()
{
    $mainnav = wp_get_nav_menu_object( 'Products' );

    if ( ! $mainnav )
    {
        $menu_id = wp_create_nav_menu( 'Products' );
        // vav item for each post type
        $types = get_post_types( array( 'exclude_from_search' => false ), 'objects' );

        foreach ( $types as $type )
        {
            if ( ! $type->_builtin )
            {
                wp_update_nav_menu_item( $menu_id, 0, array( 'menu-item-type' => 'custom', 'menu-item-title' => $type->
                    labels->name, 'menu-item-url' => get_bloginfo( 'url' ) . '/' . $type->rewrite['slug'] . '/',
                    'menu-item-status' => 'publish' ) );
            }
        }
        if ( $mainnav && ! has_nav_menu( 'primary-menu' ) )
        {
            $theme = get_current_theme();
            $mods = get_option( "mods_$theme" );
            $key = key( $mods['nav_menu_locations'] );
            $mods['nav_menu_locations'][$key] = $mainnav->term_id;
            update_option( "mods_$theme", $mods );
        }
    }
}
add_action( 'init', 'register_typenav' );
share|improve this question

1 Answer 1

You ca use the filters 'wp_nav_menu_items' and "wp_nav_menu_{$menu->slug}_items". See 'wp-includes/nav-menu-template.php', line 222.

share|improve this answer
    
These would change menu markup output, not add or remove actual menu items. –  Rarst Sep 28 '10 at 8:34
    
@Rarst: here is an example where login and logout links are added as menu items using the filter 'wp_nav_menu_items': erisds.co.uk/wordpress/… –  sorich87 Sep 28 '10 at 8:40
    
I know how it works. This is not adding menu item, this is customizing menu output. Menu items are instances of internal nav_menu_item post type, stored in database. –  Rarst Sep 28 '10 at 8:45
    
The "pre-WP3" function that Brad provided as example is customizing the menu output, so I think this is what he want to do with the new function also. –  sorich87 Sep 28 '10 at 9:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.