Title: _close_comments_for_old_post
Published: April 25, 2014
Last modified: May 20, 2026

---

# _close_comments_for_old_post( bool $open, int $post_id ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Closes comments on an old post. Hooked to comments_open and pings_open.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#parameters)󠁿

 `$open`boolrequired

Comments open or closed.

`$post_id`intrequired

Post ID.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#return)󠁿

 bool $open

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#source)󠁿

    ```php
    function _close_comments_for_old_post( $open, $post_id ) {
    	if ( ! $open ) {
    		return $open;
    	}

    	if ( ! get_option( 'close_comments_for_old_posts' ) ) {
    		return $open;
    	}

    	$days_old = (int) get_option( 'close_comments_days_old' );
    	if ( ! $days_old ) {
    		return $open;
    	}

    	$post = get_post( $post_id );

    	/** This filter is documented in wp-includes/comment.php */
    	$post_types = apply_filters( 'close_comments_for_post_types', array( 'post' ) );
    	if ( ! in_array( $post->post_type, $post_types, true ) ) {
    		return $open;
    	}

    	// Undated drafts should not show up as comments closed.
    	if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
    		return $open;
    	}

    	if ( time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
    		return false;
    	}

    	return $open;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/comment.php#L3543)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/comment.php#L3543-L3575)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#hooks)󠁿

 [apply_filters( ‘close_comments_for_post_types’, string[] $post_types )](https://developer.wordpress.org/reference/hooks/close_comments_for_post_types/)

Filters the list of post types to automatically close comments for.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_close_comments_for_old_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_close_comments_for_old_post%2F)
before being able to contribute a note or feedback.