Ordering nested comments by the latest reply

I’ve recently been working on a project that has pretty active comment threads. To improve the user experience we decided it would be much clearer to show the newest activity at the top of the comments.

Now, you may be thinking that WordPress has a setting for that?

It does not.

Via WordPress, you can order the top-level comments, but not the nested replies.

Nest Comments Scenario:

  1. 10 top-level comments (TC)
  2. each TC has its own multi-level replies (RC)

With out-the-box ordering, TC can only be sorted by oldest-to-newest or newest-to-oldest. We need TC to be sorted by RC’s timestamp.

So How Do We Sort Top-Level Comments By Their Replies?

It’s actually relatively simple:

  1. each TC gets a timestamp when it’s created – this is separate from its date because they have different uses.
  2. this timestamp is used as the orderby argument for the comments query.
  3. Then, whenever any TC or associated RCs receive a reply the TC’s timestamp is updated.

It’s that simple.


Screenshot of commenting ordering

If you’d like to implement this clean and effective enhancement with your comments, please get in touch to find out more.