Opened 13 years ago
Closed 13 years ago
#19929 closed defect (bug) (invalid)
Automatically close comments after X days: Doesn't work with custom post types
Reported by: | ndoherty13 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | Comments | Keywords: | |
Focuses: | Cc: |
Description
In the discussion settings you can set comments to close after X days. This works for regular posts, but not for custom post types. The comments on the latter stay open regardless.
Issue experienced on two separate WordPress installations, one of which had all plugins disabled and was using the default TwentyEleven theme.
To recreate the issue follow these steps:
1. Register a custom post type in the theme's functions.php file using the following code...
add_action( 'init', 'create_post_type_1' ); function create_post_type_1() { register_post_type( 'book_reviews', array( 'labels' => array( 'name' => __( 'Book Reviews' ), 'singular_name' => __( 'Book Review' ), 'all_items' => __( 'All Reviews' ), 'add_new_item' => __( 'Add New Book Review' ), 'edit_item' => __( 'Edit Book Review' ), 'view_item' => __( 'View Review' ) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'book-reviews'), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ), 'taxonomies' => array('post_tag') ) ); }
2. In your site's discussion settings, set comments to automatically close after 1 day.
3. Publish a regular blog post and a custom post type (CPT) post.
4. Check back in 24 hours and you'll find that the comments on the regular post are now closed, while the comments on the CPT post remain open.
This is expected behaviour, see #16090 and [18087].
You need to use the filter
close_comments_for_post_types
.