wp_add_trashed_suffix_to_post_name_for_post

函式
wp_add_trashed_suffix_to_post_name_for_post ( $post )
Access
Private
引數
  • (WP_Post) $post The post.
    Required:
返回值
  • (string) New slug for the post.
定義位置
相關方法
wp_add_trashed_suffix_to_post_name_for_trashed_postswp_transition_post_statuswp_is_auto_update_enabled_for_typewp_set_post_categorieswp_trash_post_comments
引入
4.5.0
棄用
-

wp_add_trashed_suffix_to_post_name_for_post: 當一個文章被移到回收站時,這個函式會在文章名稱中新增一個字尾: 該函式需要一個引數:$name。$name是文章的原始名稱。

為一個給定的文章新增一個棄用的字尾。

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

供內部使用。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
global $wpdb;
$post = get_post( $post );
if ( '__trashed' === substr( $post->post_name, -9 ) ) {
return $post->post_name;
}
add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name );
$post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed';
$wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
clean_post_cache( $post->ID );
return $post_name;
}
function wp_add_trashed_suffix_to_post_name_for_post( $post ) { global $wpdb; $post = get_post( $post ); if ( '__trashed' === substr( $post->post_name, -9 ) ) { return $post->post_name; } add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name ); $post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed'; $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); clean_post_cache( $post->ID ); return $post_name; }
function wp_add_trashed_suffix_to_post_name_for_post( $post ) {
	global $wpdb;

	$post = get_post( $post );

	if ( '__trashed' === substr( $post->post_name, -9 ) ) {
		return $post->post_name;
	}
	add_post_meta( $post->ID, '_wp_desired_post_slug', $post->post_name );
	$post_name = _truncate_post_slug( $post->post_name, 191 ) . '__trashed';
	$wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
	clean_post_cache( $post->ID );
	return $post_name;
}

常見問題

FAQs
檢視更多 >