Yoast\WP\SEO\Repositories

Indexable_Cleanup_Repository::clean_indexables_with_post_status()publicYoast 1.0

Deletes rows from the indexable table depending on the post_status.

Метод класса: Indexable_Cleanup_Repository{}

Хуков нет.

Возвращает

int|true|false. The number of rows that was deleted or false if the query failed.

Использование

$Indexable_Cleanup_Repository = new Indexable_Cleanup_Repository();
$Indexable_Cleanup_Repository->clean_indexables_with_post_status( $post_status, $limit );
$post_status(строка) (обязательный)
The post status to query.
$limit(int) (обязательный)
The limit we'll apply to the delete query.

Код Indexable_Cleanup_Repository::clean_indexables_with_post_status() Yoast 23.6

public function clean_indexables_with_post_status( $post_status, $limit ) {
	global $wpdb;

	$indexable_table = Model::get_table_name( 'Indexable' );

	// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
	$sql = $wpdb->prepare( "DELETE FROM $indexable_table WHERE object_type = 'post' AND post_status = %s ORDER BY id LIMIT %d", $post_status, $limit );

	// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared.
	return $wpdb->query( $sql );
}