如何使用wp_insert_post插入新的文章?

wp_insert_post() 函数用于插入新的文章。你需要传递一个关联数组,包含文章的各项参数,如标题、内容、分类等。例如:

$post_data = array(
‘post_title’ => ‘新的文章’,
‘post_content’ => ‘这是一篇新的文章。’,
‘post_status’ => ‘publish’, // 设置为 ‘publish’ 以立即发布文章
‘post_type’ => ‘post’, // 也可以设置为 ‘page’ 或其他自定义的文章类型
);
$post_id = wp_insert_post($post_data);

如果你想要插入更复杂的文章,例如包含多个分类或标签,你可以在 $post_data 数组中添加更多的键值对。
阅读全文

© 版权声明
THE END
喜欢就支持一下点个赞吧
点赞9 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容