WordPress.org

Ready to get started?Download WordPress

Forums

How do I remove comments from a particular category ? (8 posts)

  1. Lawcom
    Member
    Posted 4 years ago #

    I would like to remove comments from 2 categories while still allowing comments in 2 other categories ..

    So this is not a global remove comments just specific to the 2 categories that do not require comments, so would like them removed..

    Anyone got an insight ?

    Thanks ...

  2. kymac
    Member
    Posted 4 years ago #

    I can give you a query to identify the comments for a category. just replace 'my_category_slug' with your own category slug:

    SELECT *
    FROM wp_comments
    WHERE comment_post_ID
    IN (
    
    SELECT c.object_id
    FROM wp_terms a, wp_term_taxonomy b, wp_term_relationships c
    WHERE a.name = 'my_category_slug'
    AND b.term_id = a.term_id
    AND b.taxonomy = 'category'
    AND c.term_taxonomy_id = b.term_taxonomy_id
    )

    however, using this to delete comments is DANGEROUS! It will not reset the comment_count in the related posts, and I don't know what effect this will have on the site.

    IF YOU USE THIS TO DELETE COMMENTS, BACK UP YOUR DATABASE!

  3. Lawcom
    Member
    Posted 4 years ago #

    Thanks kymac ..

    It is a new site and as such no direct comments to delete, I just don't want to make them available from the off ..

    In 2 specific categories which do not require commenting on ..

  4. PBP_Editor
    Member
    Posted 4 years ago #

    You can do something more topical

    <?php if ( in_category( array( 'cat1', 'cat2') ) {
    //hide comments box
    .commentclass {display:none;}
    }
    ?>

    Look at the div class or id or whatever holds the comment box and use that for .commentclass

  5. Lawcom
    Member
    Posted 4 years ago #

    mmmmmmmmm I was thinking there must be a simply WP solution that I was just too stupid or blind to see ?

    Surely WP didn't expect every category produced would want to have comments made ? it seems like such a simple request to have.. This category, no comments..

    Is there not a plugin that I may have missed that does this ?

  6. Lawcom
    Member
    Posted 4 years ago #

    I guess the first easy step is not to allow comments per post, a bit of a hassle but not too much, but then how would I remove the 'Comments are closed.' just on that category posts ?

  7. Jack Barham
    Member
    Posted 4 years ago #

    PBP_Editor,

    I presume that code needs to go in page.php, but where abouts in that page does the it need to go.

    I am trying to manually disable comments from certain categories as well!

    Many thanks - Jack

  8. WesleyTack
    Member
    Posted 4 years ago #

    Hi, I'm also trying to turn off comments in some category pages.
    I would like to know how to do this, I also can't seem to get it to work atm, what .php file should we add this, I'm not very good at .php you see :)

    thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic