Make WordPress Core

Opened 9 years ago

Closed 9 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:


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',
			'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(
        	'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.

Change History (1)

#1 @ocean90
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

This is expected behaviour, see #16090 and [18087].

You need to use the filter close_comments_for_post_types.

Note: See TracTickets for help on using tickets.