wp_add_trashed_suffix_to_post_name_for_trashed_posts

函式
wp_add_trashed_suffix_to_post_name_for_trashed_posts ( $post_name, $post_ID = 0 )
Access
Private
引數
  • (string) $post_name Post slug.
    Required:
  • (int) $post_ID Optional. Post ID that should be ignored. Default 0.
    Required:
定義位置
相關方法
wp_add_trashed_suffix_to_post_name_for_postwp_add_editor_classic_theme_styleswp_untrash_post_set_previous_status
引入
4.5.0
棄用
-

wp_add_trashed_suffix_to_post_name_for_trashed_posts: 這個函式為所有棄用的文章在文章名稱中新增一個字尾: 該函式需要一個引數:$name。$name是文章的原始名稱。

如果任何被棄用的文章有一個給定的slug,則新增一個字尾。

儲存它想要的(即當前的)slug,這樣它就可以在文章未被毀壞時嘗試回收它。

供內部使用。”

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 );
		}
	}
}

常見問題

FAQs
檢視更多 >