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.

I'm using the walker class below, but I can't make it work with custom posts.

 class Zwp_Walker_Nav_Menu_Dynamic extends Walker_Nav_Menu {
    function end_el(&$output, $item, $depth) {
        global $wp_query;
        global $post;
        $thePostID = $post->ID;

        $subposts = get_posts( 'numberposts=10&cat=' . $item->object_id );

        if ( $subposts ) {

            $output .= '        <ul class="';

            if ( $item->object_id == $post->ID && 100 == 101) { $output .= ' sub-menu-current'; } else { $output .= ' sub-menu'; }
            $output .=  ' sub-menu-item-'.$item->object_id.'">
            ';
            foreach( $subposts as $post ) :
                setup_postdata( $post );
                $output .= '<li';
                if ( is_single() && $wp_query->post->ID == $post->ID ) { 
                    $output .= ' class="current"'; 
                }
                $output .= '><a href="'. get_permalink( $post->ID ) .'">' . get_the_title( $post->ID ) . '</a></li>
                ';
            endforeach;
            $output .= '</ul>
            ';

        }

    }
}   

I tried to change the get_posts query, but I get strange results. (Probably because the ID is missing)

$subposts = get_posts( 'numberposts=10&post_type=portfolio_work' );

The result:

Design »
    Project 1
    Project 2
Photography »
    Project 1
    Project 2
About »
    Project 1
    Project 2

This is how it should look like:

Design »
    Project 1
Photography »
    Project 2
About
share|improve this question

closed as off-topic by toscho Oct 26 '13 at 13:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
You say that you are using custom post types but your $subposts is looking for categories. Also, you set $thePostID but never use it. Can you explain those issues, and also explain how your post type is set up and what the relationship is to categories? –  s_ha_dum Nov 11 '12 at 16:21
    
s_ha_dum has some excellent questions. It also looks like you need to use both post_type=portfolio_work and cat=$item->object_id. I assume Design and Photography are categories and project 1 and 2 are 'portfolio_work' type posts. If so, you probably need both cat and post type, since get_posts sets post_type to 'post' by default. –  John P Bloch Dec 25 '12 at 2:48
3  
if ( $item->object_id == $post->ID && 100 == 101) … what? This will never do anything. Please explain your problem better. In its current form it is impossible to answer. –  toscho Jan 11 '13 at 20:41

1 Answer 1

  1. Fix 100 == 101 in you if statement (always false)
  2. Try $subposts = get_posts( 'numberposts=10&post_type=portfolio_work&cat=' . $item->object_id );
share|improve this answer

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