Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a custom post type + taxonomies in a podcast solution for a client. The setting (settings >> discussion) for comments is set to "allow comments". When I add / edit posts under the "posts" tab, comments are enabled by default.

However, when I add / edit posts under the custom post type (podcast) - comments are disabled by default.

The user can still manually enable comments for each post, but this is obviously not ideal. Thoughts?

UPDATE: Relevant Code in functions.php

function create_my_post_types() {
register_post_type( 'podcast',
    array(
        'labels' => array(
            'name' => __( 'Podcast' ),
            'singular_name' => __( 'Podcast' ),
            'new_item' => __( 'New Episode' ),
            'add_new_item' => __( 'Add New Episode' )
        ),
        'public' => true,
        'hierarchical' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/assets/podcast-icon.png', // 16px16
        'menu_position' => 9,
        'supports' => array( 'title', 'editor', 'comments', 'post-templates'),
        'register_meta_box_cb' => 'add_podcast_metaboxes' // This registers the metabox that we'll add later.
    )
);

}

share|improve this question
add comment

3 Answers

up vote 6 down vote accepted

Ok - so I solved this. Here is what appears to be the problem.

Comments are disabled by default for custom-post-types. This happens even if you have them enabled in the overall settings

To fix it, all I had to do was the following:

  1. In SETTINGS > DISCUSSION uncheck the "Allow people to post comments on new articles" setting.
  2. Click "Save Changes"
  3. Now go back and re-check "Allow people to post comments on new articles"
  4. Click "Save Changes"

It seems that for custom post types you need to kind of kick-start this setting. All new posts for created custom-post-types will have the box enabled by default. Existing posts will retain their previous setting. I'm assuming it's the same for allowing trackbacks. Hopefully this helps someone...

share|improve this answer
    
Mark this answer as The Answer. –  toscho Jan 10 '12 at 22:26
add comment

Just taking a random stab but do you have to add "comments" to the supports array parameter, in the register_post_type() call?

share|improve this answer
    
already there - I can see the discussion panel AND use it to enable comments on a per-post basis, but it is unchecked by default in spite of my site-wide settings having comments enabled. –  timshutes Jan 10 '12 at 21:47
add comment

This is the default state.. you need to change the "Supports line" where you build your custom post type..

Meaning this line:

// or something similer that starts the same

'supports' => array('title','editor','author','excerpt','revisions'),

To this line:

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

Hope this helps.
Cheers, Sagive.

ADDED FUNCTION (INSIDE FUNCTIONS FILE):

function default_comments_on( $data ) {
    if( $data['post_type'] == 'your_custom_post_name' ) {
        $data['comment_status'] = 1;
    }

    return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_on' );
share|improve this answer
    
Hi - I already have that code entered correctly in functions.php. My understanding is that the comments box wouldn't even appear if it wasn't enabled in the way you describe. My problem is that it appears, but it's unchecked by default even though I have set the default to be enabled in Settings > Discussion. –  timshutes Jan 10 '12 at 15:03
    
ohh.. so i think its only you that see that option that way... its your prefrences.. make sure your check both option (or the one you want) in the Discussion module (see image: en.support.files.wordpress.com/2009/12/…) and you should be all set.. More information about those setting can be found here: en.support.wordpress.com/enable-disable-comments –  Sagive SEO Jan 10 '12 at 15:37
    
I guess I haven't been clear... those are already checked and the result is that comments are enabled for all of my posts EXCEPT the custom post types which still have to be manually edited. It feels like a bug, or something I need to add in functions.php but I can't find anything in the codex. –  timshutes Jan 10 '12 at 21:42
    
wait - no that time I misunderstood - you're talking about the module in the edit post window. I can definitely enable comments or trackbacks by checking those boxes. HOWEVER, I would like those boxes to be checked by default so my client doesn't have to remember to do it EVERY time they post a new podcast episode. I thought that enabling comments in the Discussion >> Settings area of Admin would take care of it, but it's still unchecked by default. –  timshutes Jan 10 '12 at 21:46
    
I Still thinks that if it appears (the comments / trackback box) and you would to save the post with them it would become the default state... BUT i have added some code to my original answer -tried it on 3.01 which i am on.. hope it helps –  Sagive SEO Jan 10 '12 at 23:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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