Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Automatic Archive Settings for Topics

@robin-w

Moderator

Put this in your child theme’s function file – or use

Code Snippets

change the ‘-10 days’ to say ‘-90 days’ if you want 3 months

register_activation_hook(__FILE__, 'bbpress_topic_scheduler');

add_action('bbpress_daily_event', 'bbpress_close_old_topics');

function bbpress_topic_scheduler() {
 wp_schedule_event(time(), 'daily', 'bbpress_daily_event');
}

function bbpress_close_old_topics() {
	// Auto close old topics
	$topics_query = array(
		'author' => 0,
		'show_stickies' => false,
		'parent_forum' => 'any',
		'post_status' => 'publish',
		'posts_per_page' => -1
	);
	if ( bbp_has_topics( $topics_query ) )
		while( bbp_topics() ) {
			bbp_the_topic();
			$topic_id = bbp_get_topic_id();
			$last_active = strtotime( get_post_meta( $topic_id, '_bbp_last_active_time', true ) );
			if ($last_active < strtotime( '-10 days') )
				bbp_close_topic( $topic_id );
		}
}
Skip to toolbar