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,这样它就可以在文章未被销毁时尝试回收它。

供内部使用。

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
查看更多 >