• InHouse

    (@inhouse)


    Hello, I have registered a post type ‘member’ which supports ‘title’ and ‘revisions’ and nothing else. No comments.

    
    'supports' => array( 'title', 'revisions' ),
    

    When editing a ‘member’ post the Discussion and Comments meta boxes are not only present but “Allow comments” is checked (enabled)! How could this be when the post type does not support comments? I have also tried manually disabling comments via my theme’s functions.php file.

    
    // Remove post type support
    add_action( 'init', 'my_custom_init' );
    function my_custom_init() {
    	remove_post_type_support( 'page', 'thumbnail' );
    	remove_post_type_support( 'page', 'comments' );
    	remove_post_type_support( 'tribe_events', 'comments' );
    	remove_post_type_support( 'tribe_events', 'author' );
    	remove_post_type_support( 'member', 'comments' );
    	add_theme_support( 'post-thumbnails', array( 'tribe_events' ) ); 
    }
    

    All the other remove_post_type_support lines work as expected.

    What could be enabling comments for this post type? I switched from my custom theme to the TwentyNineteen theme. I’m running WP 5.1 with all plugins up to date. Important to note this issue was occuring yesterday with WP 5.0.x prior to updating to 5.1.

    Thanks in advance for any help or info!

Viewing 7 replies - 1 through 7 (of 7 total)
  • kinjaldalwadi

    (@kinjaldalwadi)

    Hello inhouse,

    You have to add one more parameter ‘comments’ on supports like below code:
    ‘supports’ => array( ‘title’, ‘revisions’, ‘comments’ ),

    Thread Starter InHouse

    (@inhouse)

    I do not want the plugin to support comments. I believe you misread my request. I do not want comments so I have intentionally omitted ‘comments’ from the ‘supports’ list.

    kinjaldalwadi

    (@kinjaldalwadi)

    Yes, You can disable from backend as well by following below steps.
    Please review attached screesnhot in below link:

    2019-03-07_1523

    For applying steps accordingly screenshot, first its require to enable comments as per the below:

    ‘supports’ => array( ‘title’, ‘revisions’, ‘comments’ ),

    Thread Starter InHouse

    (@inhouse)

    Again, I want to disable comments, not enable.

    As you see below, the plugin should not be supporting comments but somehow it does.

    'supports' => array( 'title', 'revisions' ),

    ‘comments’ are intentionally omitted from the ‘supports’ line but comments are still supported for this plugin. Something is not right!

    Maybe too late, but here is the solution in case you still need it.

    It seems that there is no possibility to disable comments globally by post type in wordpress, but there is a filter called “comments_open” which let’s you enable or disable comments on per post basis (https://www.shivarweb.com/10676/turn-off-comments-wordpress/). The filter accepts post_id as the second argument and you can use that post ID to find out the post type and then enable or disable comments functionality. Actually, it gives control over comments_open() function primarily used in wordpress template files:

    function my_prefix_comments_open( $open, $post_id ) {
        $post_type = get_post_type( $post_id );
        // allow comments for built-in "post" post type
        if ( $post_type == 'post' ) {
            return true;
        }
        // disable comments for any other post types
        return false;
    }
    add_filter( 'comments_open', 'my_prefix_comments_open', 10 , 2 );

    Have a nice day ??

    @wndrlstuser THANK YOU that works perfectly for me ??

    I’m glad it helped you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Cannot Disable Comments for my Custom Post Type’ is closed to new replies.