0

I want to sort all comment descending programmatically, I found this Comments sorted by oldest first but I dont want use those modules or views solution.
anybody know how can I sort comment descending programmatically?
I means comments in below node(contents) , first ideal is get comments related to node by query and set orderby DESC but everything show reversed in thread mode, replies come above comment !!!.

2
  • Comments attached to a node or All comments in the website ?
    – Anil Sagar
    Commented Mar 1, 2014 at 13:45
  • comments attached to node in view of node
    – Yuseferi
    Commented Mar 1, 2014 at 13:53

1 Answer 1

0
<?php
$query = db_select('comment') ->fields('comment', array('cid')) ->condition('nid', arg(1), '=');
$query->orderBy('created', 'DESC');
$result = $query->execute();
$cids = $result->fetchCol();
$comments=comment_load_multiple($cids);
foreach($comments as $comment)  {
  //do some stuff with the comment
}
?>
3
  • 1
    but do u think about how they come in thread mode ? replay placed above comment !!! (everything reversed>, tnx for you attention but this is not complete solution.
    – Yuseferi
    Commented Mar 1, 2014 at 17:08
  • Can you update your question with above details which will help others ? I mean thread mode..
    – Anil Sagar
    Commented Mar 1, 2014 at 17:15
  • sure , I will update it .
    – Yuseferi
    Commented Mar 1, 2014 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.