Created
August 9, 2012 16:22
-
-
Save alloyking/3305602 to your computer and use it in GitHub Desktop.
Wordpress get replies and child replies for a comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getReplies($comment_post_id, $commentID){ | |
$wp_comments = $this->wpdb->prefix . "comments"; | |
$childData = array(); | |
$data = $this->wpdb->get_results( "SELECT * FROM $wp_comments | |
WHERE $wp_comments.comment_post_ID = $comment_post_id AND $wp_comments.comment_parent != 0"); | |
$dataLength = count($data); | |
for($i = 0; $i< $dataLength; $i++){ | |
if($data[$i]->comment_parent == $commentID) { | |
array_push($childData, $data[$i]); | |
} | |
} | |
for($t = 0; $t<count($data); $t++){ | |
for($r = 0; $r<count($childData); $r++){ | |
if($data[$t]->comment_parent == $childData[$r]->comment_ID){ | |
array_push($childData, $data[$t]); | |
} | |
} | |
} | |
return $childData; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment