1

I've set up a custom WP Comments Query that serves approved comments on posts ordered by date (basic stuff) and everything works fine except the fact that comments are displayed below each other and I'd like them to be nested — like if I was using wp_list_comments().

Is there any template file/function to output comment template to the query so the comment will have a basic wp comment html structure with all the wp classes and reply links?

The reason why I can't use the wp_list_comments() is that it doesn't allow to set the post_id which I need to set as I'm fetching posts via AJAX, and this function doesn't work properly outside the loop...

Any help/idea is very welcome, thanks a bunch!

1

you can pass an array of WP_Comment objects into wp_list_comments as second argument.

// Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );

// Display
wp_list_comments(array(), $comments);
  • That works, but I have another question... Who is the best? Wait... I know! You are! Nah, seriously thanks dude I've been looking for this the whole day and this comments is perfect, exactly, what I'm looking for. Fixed all my problems! Many thanks! – pbe Feb 19 '17 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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