Darfreak Posted August 14, 2015 Share Posted August 14, 2015 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]; } Quote Link to comment https://forums.phpfreaks.com/topic/297777-comments-order-asc-desc/ Share on other sites More sharing options...
akphidelt2007 Posted August 14, 2015 Share Posted August 14, 2015 What does function get_comments look like? Quote Link to comment https://forums.phpfreaks.com/topic/297777-comments-order-asc-desc/#findComment-1518761 Share on other sites More sharing options...
Solution Ch0cu3r Posted August 14, 2015 Solution Share Posted August 14, 2015 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); Quote Link to comment https://forums.phpfreaks.com/topic/297777-comments-order-asc-desc/#findComment-1518762 Share on other sites More sharing options...
akphidelt2007 Posted August 14, 2015 Share Posted August 14, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/297777-comments-order-asc-desc/#findComment-1518763 Share on other sites More sharing options...
Darfreak Posted August 14, 2015 Author Share Posted August 14, 2015 Thanks Ch0cu3r, That worked great for me! Thanks to everyone else as well. Quote Link to comment https://forums.phpfreaks.com/topic/297777-comments-order-asc-desc/#findComment-1518764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.