Jump to content

Comments, Order Asc, Desc


Darfreak
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi friends,

I'm using Kalins pdf in Wordpress.

Where in the code below can I arrange these comments using "ORDER by comment_date DESC"?

I have tried for weeks and I keep getting blank pages.

I'll appreciate your input:

 

function commentCallback($matches) {
   
    if(defined("KALINS_PDF_

COMMENT_CALLBACK")){
      return call_user_func(KALINS_PDF_COMMENT_CALLBACK);
    }
   
    global $post;
   
    $comments = get_comments('status=approve&post_id=' .$post->ID);
   
    $commentString = $matches[2];
   
    foreach($comments as $comment) {
      if($comment->comment_author_url == ""){
        $authorString = $comment->comment_author;
      }else{
        $authorString = '<a href="' .$comment->comment_author_url .'" >' .$comment->comment_author ."</a>";
      }
     $commentString = $commentString .'<p>' .$authorString ." - " .get_comment_date(null, $comment->comment_ID) ." @ " .get_comment_date(get_option('time_format'), $comment->comment_ID) ."<br />" . $comment->comment_content ."</p>";
    }
   
    //get_comment_date('m-d-Y @ g:i A', $comment->comment_ID)
   
    return $commentString .$matches[4];
  }
Link to comment
Share on other sites

  • Solution

Asumming get_comments is a wordpress function, then ;ooking at the wordpress documentation for the get_comments, you set the order clause in the argument string

$comments = get_comments('status=approve&post_id=' .$post->ID.'&orderby=comment_date&order=DESC');

// alternatively can be written as
$args = array(
    'status' => 'approve',
    'post_id' => $post->ID,
    'orderby' => 'comment_date',
    'order' => 'DESC'
);
$comments = get_comments($args);
Link to comment
Share on other sites

Someone might be able to spot the problem, but I for one can't at first glance without knowing more information.

 

If I have problems in my code I like going section by section using echo "here"; exit;

 

Or if you think there should be data than echo the variable or print_r($yourdata); exit;

 

Like what does $matches show, what does $comments show? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.