Listing recent comments excluding a post ID (5 posts)

  1. houseofstrauss
    Posted 6 years ago #

    In my sidebar I'm using from the codex

    $comments = get_comments('post_id=-15');
      foreach($comments as $comm) :
    But I want to EXCLUDE all comments from post ID 15 You will see I've added a '-' symbol, but it does not work to exclude. How do I do this please?


  2. Get comments doesn't work that way.

    Maybe this similar post will help: http://wordpress.org/support/topic/314109?replies=7

  3. houseofstrauss
    Posted 6 years ago #

    Thanks ipstenu, but the line `$comments = get_comments('post_id=15');
    ` is correct to filter comments for only one id. I already use this and it works. My ID is in fact a page, not a post so I cant use a category as the other post suggests.

    There must be a way to prevent comments being listed for a specific page ID without using a plugin?

  4. Sorry, I was unclear. What I'm saying is that the NEGATIVE sign doesn't work that way :) There's an include, but no exclude. I'd open trac and put this in as a request to add to WP.

    This code (which is from the link I gave you) skips category 112, so I suspect you could re-jigger it to have it check for in-post instead:

    global $comment; if ( $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved='1' AND comment_type='' ORDER BY comment_date_gmt DESC LIMIT 10") ) : ?>
    <?php foreach ($comments as $comment) {
    if (in_category( '112', $comment->comment_post_ID ){
      echo '<li>' . sprintf('%s <span style="text-transform: lowercase;">on </span>%s', get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>');
      echo '</li>'; } ?>
    <?php endif; ?>
  5. houseofstrauss
    Posted 6 years ago #

    thanks, I see what you mean now, Ill see if I can work it out. Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic