0

Trying to display the latest 50 comments (global, from all the posts) on a page (page.php)

I am using this code:

  <?php $comments = get_comments('status=approve&number=50&type=comment&hierarchical=threaded');
      foreach($comments as $comment) :?>
      <?php $post = get_post($comment->comment_post_ID, 'OBJECT'); ?>
      <li>  <a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo($comment->comment_ID);?>">
         <?php echo $post->post_title; ?>
          </a> 
<?php echo($comment->comment_content);?> 
      </li> <br/>
    <?php endforeach; ?>

It works fine, it shows the comments, but it doesn't show comment replies - I want to show replies too

`hierarchical=threaded` 

should do the trick, but it doesn't. maybe because The parameter is ignored (forced to false) when $fields is 'ids' or 'counts' But I don't know how to fix that

thanks!

0

Try with array method, using reply post type with its parent.

<?php
$args = array(
   'post_type'           => 'reply',
   'status'              => 'approve',        
   'post_parent'         => $postID,                   
   'posts_per_page'      => 50,                        
   'orderby'             => 'date',                        
   'order'               => 'ASC',                         
   'hierarchical'        => true,
   'ignore_sticky_posts' => true,                          
);

foreach(get_comments($args) as $comment) :?>
| improve this answer | |
  • thanks, but I'm not sure how to use this. If I integrate it into my code, it will only display a link to the current page. I need to display global comments (sitewide) not just current page – whitelord Jan 14 at 9:07
  • Just replace this with line 1 and 2 from your code – Fadi Chamoun Jan 14 at 12:40
  • If I do that, it displays nothing – whitelord Jan 14 at 22:49
  • Try then replacing: 'post_type' => 'reply' width: 'type' => 'comment' – Fadi Chamoun Jan 17 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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