# wp_scheduled_delete()

URL: https://chugunov.pro/api-wordpress/functions/wp_scheduled_delete/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.9.0.

## Сигнатура

```php
wp_scheduled_delete()
```

## Описание

Значение по умолчанию для EMPTY_TRASH_DAYS — 30 (дней).

## Исходный код

Файл: `wp-includes/functions.php:6884`

```php
function wp_scheduled_delete() {
	global $wpdb;

	$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );

	$posts_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );

	foreach ( (array) $posts_to_delete as $post ) {
		$post_id = (int) $post['post_id'];
		if ( ! $post_id ) {
			continue;
		}

		$del_post = get_post( $post_id );

		if ( ! $del_post || 'trash' !== $del_post->post_status ) {
			delete_post_meta( $post_id, '_wp_trash_meta_status' );
			delete_post_meta( $post_id, '_wp_trash_meta_time' );
		} else {
			wp_delete_post( $post_id );
		}
	}

	$comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );

	foreach ( (array) $comments_to_delete as $comment ) {
		$comment_id = (int) $comment['comment_id'];
		if ( ! $comment_id ) {
			continue;
		}

		$del_comment = get_comment( $comment_id );

		if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
			delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
			delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
		} else {
			wp_delete_comment( $del_comment );
		}
	}
}
```

## История изменений

- 2.9.0 — Introduced.

## Связанные

Использует: [`wp_delete_post`](https://chugunov.pro/api-wordpress/functions/wp_delete_post/), [`delete_post_meta`](https://chugunov.pro/api-wordpress/functions/delete_post_meta/), [`wp_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_delete_comment/), [`delete_comment_meta`](https://chugunov.pro/api-wordpress/functions/delete_comment_meta/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/), `wpdb::get_results`, `wpdb::prepare`, [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_scheduled_delete/
