WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom post type called Products, on the product pages i have a menu in the left sidebar. This menu is made up of categories for the products.

Is it possible to have my products automatically added to the category menu based the category of the product?

For example, i make a product, i give it a category of blue. Where blue appears in the menu the product will automatically be added underneath blue.

Is this possible?


Update: To be more clear i'm using a plugin called Jquery Accordion Menu and the menu uses a widget. It still uses the built-in wordpress menu system. The Jquery Accordion Widget effectively just styles the menu, in the widget settings you pick what menu you want it to show.

I've found this code inside the plugin file after the comments below. I don't know if it's any help.

        function widget($args, $instance) {
            extract( $args );
            // Get menu

            if(! isset($instance['speed']) ){ $instance['speed'] = 'slow'; }

            $widget_options = wp_parse_args( $instance, $this->defaults );
            extract( $widget_options, EXTR_SKIP );

            $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );

            if (!$nav_menu)

            $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);

            $classMenu = ($instance['classMenu'] != '') ? $instance['classMenu'] : 'menu';

            echo $args['before_widget'];

            if ( !empty($instance['title']) )
                    echo $args['before_title'] . $instance['title'] . $args['after_title'];


            <div class="dcjq-accordion" id="<?php echo $this->id.'-item'; ?>">

                                            'fallback_cb' => '',
                                            'menu' => $nav_menu,
                                            'container' => false,
                                            'menu_class' => $classMenu


            echo $args['after_widget'];

EDIT 2: If i can get this working without the plugin then that's great. I just need some sort of menu that displays categories and the pages for that category automatically.

share|improve this question

Yes, it's possible.

Depending on the way you build your menu, you'd have to call the posts like this (fill in placeholders):

// Call/Query the posts related to the category:
$your_cat_related_cpts = get_posts( array(
     'post_type' => 'YOUR_CUSTOM_POST_TYPE'
    ,'category' => 'YOUR_CATEGORY'
) );
// Append them to your menu:
foreach ( $your_cat_related_cpts as $content )
    echo $content->post_title;
share|improve this answer
Thanks. 2 Questions. 1) where do i put this code? 2) Will this only work for one category? – Corbula Oct 9 '11 at 14:28
I've tried this in functions.php but it didn't work. It put the post title at the top of every page and it messed up the layout of the page the post is on. It also didn't add it to the menu. I've made the menu by using the built-in wordpress menu system and adding all of the categories to it. – Corbula Oct 9 '11 at 18:49
How about showing your menu code? – kaiser Oct 9 '11 at 19:25
Sorry can you be more specific? I've just used the menu system that comes with wordpress and added categories to it. When you say menu code do you mean the html source code, or something else? – Corbula Oct 9 '11 at 20:36
HOW did you add the menu in your template? The menu won't just pop up if you play around. You need to add_theme_support(), define and call the wp_nav_menu(), etc. – kaiser Oct 9 '11 at 21:59
up vote 0 down vote accepted

I've found this plugin that does exactly what i needed.


share|improve this answer

Your Answer


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.