WordPress根据文章ID设置文章类型函数:set_post_type

WordPress函数set_post_type为指定ID的文章设置文章类型。

set_post_type( int $post_id, string $post_type = 'post' )

函数参数

$post_id

整数

要修改的文章ID

$post_type

字符串

文章类型

函数使用示例

$post_id = 3546;
 
if ( set_post_type( $post_id, 'page'  ) ) {
	echo "文章{$post_id}的类型现在为page";
} else {
	echo '无法将文章转换为page';
}

扩展阅读

set_post_type()函数位于:wp-includes/post.php

相关函数:

  • clean_post_cache()
  • sanitize_post_field()
阿里云