How to resort a topic's messages by date?

I’ve imported a large older mailing list into Discourse and found (after merging various threads that were not initially properly identified to be part of a parent thread) that threads have become disordered. Many earlier dated thread messages are being shown in Discourse AFTER parent threads that have earlier dates.

Is there a method to resort threads so that they are ordered by date from oldest (original post) to newest?


No. The problem is that topics are sorted in post-id order. And, as you have described, you have imported posts in an order other than the order that they should have been created. I am afraid that the only proper solution is to fix the import so that posts are imported in the proper order. It sounds like, though, that all you’d need to do is wipe the database and re-run the import script.

(Or other “solutions” include don’t care about the post order, it’s old stuff that no one is going to read anyway, and contrive to, for each topic, delete all of the existing posts and re-create them in the correct order.)

1 Like

Hmm, these have been in place now for quite some months. I don’t really believe the deletion and reimportation is an appropriate solution. I wonder if we can build a plugin that will allow post-id reordering… hmm.

1 Like

Oh. That’s too bad. Anything is possible, I suppose, but that will affect performance on the whole site forever…

You could conceivably delete those topics and the associated custom fields and then run the script again. You’d want to test very carefully on a staging site before you do it on your live data.

1 Like

If the post-ids are reordered then I wouldn’t think it would permanently affect it. I suppose another option would be a plugin that would simply sort a thread by date as it’s queried…

Right. If you delete and recreate all the posts on the right order you’ll be all set.