wp_add_trashed_suffix_to_post_name_for_trashed_posts()WP 4.5.0

Adds a suffix if any trashed posts have a given slug.

Store its desired (i.e. current) slug so it can try to reclaim it if the post is untrashed.

For internal use.

Хуков нет.

Возвращает

null. Ничего.

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

wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID );
$post_name(строка) (обязательный)
Post slug.
$post_ID(int)
Post ID that should be ignored.

Список изменений

С версии 4.5.0 Введена.

Код wp_add_trashed_suffix_to_post_name_for_trashed_posts() WP 6.1.1

function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) {
	$trashed_posts_with_desired_slug = get_posts(
		array(
			'name'         => $post_name,
			'post_status'  => 'trash',
			'post_type'    => 'any',
			'nopaging'     => true,
			'post__not_in' => array( $post_ID ),
		)
	);

	if ( ! empty( $trashed_posts_with_desired_slug ) ) {
		foreach ( $trashed_posts_with_desired_slug as $_post ) {
			wp_add_trashed_suffix_to_post_name_for_post( $_post );
		}
	}
}