I've spent a LONG time trying to get nested custom post types working. Here's the setup. I have two custom post types, topics and replies. I'm looping through topics and inside the topic loop I'm placing the reply loop. So far so good. Topics and replies display fine. But I want to nest the replies in a hierarchical fashion. Lots of reading tells me I probably need a custom post type walker. I've been trying to make such a walker but not successfully. Most walkers are for navs or for pages, not custom posts. Or perhaps to use a recursive function?

Here are the current working reply args:

 $args = array(
     'post_type'        => 'reply', // custom post type
     'orderby'          => 'menu_order',
     'order'            => 'ASC',
     'post_parent'      => $topic_id, //the topic
 $loopReply = new WP_Query( $args );

 ////////  REPLY LOOP /////////////////////////////////////////////////////////

 while( $loopReply->have_posts() ): $loopReply->the_post(); global $post;

1 Answer 1


I've found a solution which works great. I ended up copying the bbPress Reply Walker class which was an extension of the WordPress walker class, and modifying some of the parameters to meet my needs. I had to also make my own function for listing replies, similar to bbPress's list replies function. The list replies function had custom args as follows:

            $args = array(
                'post_type'           => 'reply',                   
                'post_parent'         => $postID,                   
                'posts_per_page'      => 50,                        
                'orderby'             => 'date',                        
                'order'               => 'ASC',                         
                'hierarchical'        => true,
                'ignore_sticky_posts' => true,                          

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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