[wp-hackers] Retrieving all the comments in a thread

Dino Termini dino at duechiacchiere.it
Mon Sep 19 18:21:58 UTC 2011


Hi all,

I was wondering if Wordpress has a built-in method to get all the 
comments in a given thread. Let's say I have

- post
-- comment 1 [ID = 1]
--- reply 1 to comment 1 [ID = 2]
--- reply 2 to comment 1 [ID = 3]
--- reply 3 to comment 1 [ID = 4]
-- comment 2 [ID = 5]
-- comment 3 [ID = 6]
--- reply 1 to comment 3 [ID = 7]
--- reply 2 to comment 3 [ID = 8]
---- reply 1 to reply 2 to comment 1 [ID = 9]
---- reply 2 to reply 2 to comment 1 [ID = 10]

Given any comment ID, I'd like to get all the comment IDs in the same 
thread. So for ID = 3, I'd get {1, 2, 3, 4}, and so on. How would you 
accomplish something like this in Wordpress, since the only available 
relationship between comments is parent/son and there's no recursion in 
Mysql?\

Thanks,
Dino


More information about the wp-hackers mailing list