Custom post type: can't enable comments by default

admin2025-01-07  4

I want to enable comments for custom post types just like they are for standard posts, but can't seem to get it to work.

In functions.php, as part of registering my custom post type, I have this:

'supports' => array('title', 'author', 'thumbnail', 'comments', 'revisions'),

In my single post type template I have this:

<?php comments_template( '', true ); ?>

But on the edit screen "allow comments" is un-checked by default which results in a "comments are closed" message on the front end. When I check "allow comments" then comments are enabled on the front end, but I really don't want to tell my client he has to manually check that box for every new post.

I tried the recommendations here:

Why are the comments disabled by default on my custom_post_types?

But it didn't work for me.

I tried disabling all plugins. Didn't work.

Using WP 3.6.

Any suggestions? Thanks in advance.

I want to enable comments for custom post types just like they are for standard posts, but can't seem to get it to work.

In functions.php, as part of registering my custom post type, I have this:

'supports' => array('title', 'author', 'thumbnail', 'comments', 'revisions'),

In my single post type template I have this:

<?php comments_template( '', true ); ?>

But on the edit screen "allow comments" is un-checked by default which results in a "comments are closed" message on the front end. When I check "allow comments" then comments are enabled on the front end, but I really don't want to tell my client he has to manually check that box for every new post.

I tried the recommendations here:

Why are the comments disabled by default on my custom_post_types?

But it didn't work for me.

I tried disabling all plugins. Didn't work.

Using WP 3.6.

Any suggestions? Thanks in advance.

Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Aug 24, 2013 at 1:45 dadradadra 332 gold badges3 silver badges10 bronze badges 1
  • It's looking strange and as you have said you have tried all recommendations from this question wordpress.stackexchange.com/questions/38405/… Can you just copy your custom post type registration code from functions.php file and add it into another theme line twentythirteen and check whether the same happens or not? – Vinod Dalvi Commented Aug 24, 2013 at 8:59
Add a comment  | 

3 Answers 3

Reset to default 0

I made no additional changes, but somehow it's working correctly now. Perhaps the system had to sleep on it or something, but when I checked again this morning everything was working properly.

I believe that these instructions do work:

Why are the comments disabled by default on my custom_post_types?

Essentially kick-starting the comments in SETTINGS > DISCUSSION, much like clicking "save changes" in SETTINGS > PERMALINKS resets the system if you run into a 404 after registering custom post types.

Check your settings in discussion

1) Dashboard -> Settings -> Discussion -> Default article settings -> 'Allow people to post comments on new articles' should be checked.

By settings this you will get 'Allow comments' default selected.

please try to modify your custom post-type registration code to enable comments by default.

By setting 'comments' => true in the arguments array, comments will be enabled by default for your custom post type.

$args = array(
    'labels'             => $labels,
    'public'             => true,
    'publicly_queryable' => true,
    'show_ui'            => true,
    'show_in_menu'       => true,
    'query_var'          => true,
    'rewrite'            => array( 'slug' => 'your-post-type' ),
    'capability_type'    => 'post',
    'has_archive'        => true,
    'hierarchical'       => false,
    'menu_position'      => null,
    'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
    'comments'           => true, // Enable comments by default
);

register_post_type( 'your_post_type', $args );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736260641a680.html

最新回复(0)