What I'm trying to achieve:
Topic (1)
Reply to 1 (2)
--Reply to 2 (3)
--Reply to 2 (4)
----Reply to 4 (5)
----Reply to 4 (6)
Reply to Topic 1 (7)
----Reply to 6 (7)
------Reply to 7 (8)
---Reply to 8 (9)
------Reply to 8 (10)
What I currently have is more like
Topic (1)
Reply to 1 (2)
Reply to 2 (3)
Reply to 4 (5)
Reply to 7 (6)
Reply to 6 (7)
Reply to 4 (8)
Reply to 8 (9)
Reply to Topic 1 (10)
Reply to 8 (11)
Reply to 2 (12)
Above is a sample structure of a forum I built using Wordpress and bbPress. There are topics and replies, both which are custom post types. I'm able to display the topics with replies fine, but I wish to sort them in a nested/threaded view. Rather than simply having the replies all appear in order of date or id, I want them to appear nested beneath the reply which is the parent.
I hope that makes sense. Basically it is threaded topics and replies just like facebook does.
Below is my args and query for the replies, which is inside the topic WP_Query loop.
$args = array(
'post_type' => 'reply', // custom post type
'posts_per_page' => '50',
'orderby' => 'post_parent',
'post_parent' => $topic_id,
'meta_query' => array(
'relation' => 'OR',
array(
'key'=> $topic_id,
),
array(
'key'=>'_bbp_reply_to',
'compare' => 'NOT EXISTS'
),
array(
'key'=>'_bbp_reply_to',
'compare' => 'EXISTS',
),
),
'orderby' => 'meta_value_num',
'order' => 'ASC',
);
//global $wpdb;
$loopReply = new WP_Query($args);
I hope this isn't too unclear. I've found other close questions regarding wordpress postmeta sorting, but this is an odd one. You see the meta key _bbp_reply_to ONLY shows up if it is a reply to a reply. It doesn't happen if it is a reply to a topic. This is why I "think" I need to array key exists portion of the args.
IN SHORT
Need a set of $args, if possible to do nested replies. Or do I have to do my own manual sql to achieve this?
EDIT: See my comment. I changed the title a bit as I believe to achieve this a custom Wordpress Walker Class implementation is likely the solution.