如果我运行以下代码,它会返回一个int(0)。Wordpress创建帖子,但帖子标题为空,尽管$name变量已填充。
$postID = wp_insert_post(array(
"post_title" => $name,
"post_status" => "publish",
"post_type" => "mycustomposttype",
), true);
var_dump($postID);
" $name, ="" \"post_status\"=">" \"publish\", ="" \"post_type\"=">" \"mycustomposttype\", ),="" true); var_dump($postid);"="">
如果我运行以下代码,它会返回一个int(0)。Wordpress创建帖子,但帖子标题为空,尽管$name变量已填充。
$postID = wp_insert_post(array(
"post_title" => $name,
"post_status" => "publish",
"post_type" => "mycustomposttype",
), true);
var_dump($postID);
根据法典上的注释wp_insert_post()
post_title and post_content are required
如果希望内容为空,可以编写wp_insert_post
args数组因此:$postID = wp_insert_post(array(
"post_title" => $name,
"post_status" => "publish",
"post_content => " ",
"post_type" => "mycustomposttype",
), true);