Skip to content

Instantly share code, notes, and snippets.

@alloyking
Created August 9, 2012 16:22
Show Gist options
  • Save alloyking/3305602 to your computer and use it in GitHub Desktop.
Save alloyking/3305602 to your computer and use it in GitHub Desktop.
Wordpress get replies and child replies for a comment
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