'topic', 'post_status' => 'publish', 'posts_per_page' => 50, // Batch to avoid timeouts 'meta_query' => [ [ 'key' => '_bbp_last_active_time', 'value' => $cutoff, 'compare' => '<', 'type' => 'DATETIME', ], ], 'fields' => 'ids', ]; $stale_topics = get_posts( $args ); if ( ! empty( $stale_topics ) ) { foreach ( $stale_topics as $topic_id ) { // Skip already closed topics (though query checks post_status=publish, bbp_is_topic_closed checks meta) if ( bbp_is_topic_closed( $topic_id ) ) { continue; } // Skip sticky topics (they're intentionally persistent) if ( bbp_is_topic_sticky( $topic_id ) || bbp_is_topic_super_sticky( $topic_id ) ) { continue; } bbp_close_topic( $topic_id ); // Add a meta flag so admins know it was auto-closed update_post_meta( $topic_id, '_frmx_auto_closed', current_time( 'mysql' ) ); } } } } // Instantiate the class. new forumax_auto_close_topics();