WordPress 稿件插入函数wp_insert_post
WordPress 文章插入函数wp_insert_post
##WordPress 文章插入函数wp_insert_post##
该函数可在数据库中插入文章(及页面)。
它可以进行处理变量,检查操作,填充日期/时间等缺失变量等工作。
该函数以对象作为变量,返回已创建文章的编号(出错时返回0)。
#使用方法#
<?php wp_insert_post( $post, $wp_error ); ?>
//参数$post
参看 http://amhere.iteye.com/admin/blogs/1956705
//参数$wp_error
(布尔型) (可选) 失败时是否返回WP_Error对象
#例子#
// 创建一个文章对象
$my_post = array(
‘post_title’ => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
//入库
wp_insert_post( $my_post );
//源码位置
wp_insert_post() 位于 wp-includes/post.php
//返回的值
若文章成功加入数据库,返回文章编号。否则返回0.