wp insert post 插入文章到数据库

在 wordpress 主题目录下的 index.php 文件中,添加如下代码

<?php get_header(); ?>

<?php
 // 创建文章对象
$my_post = array(
  'post_title'    => '我的测试文章',
  'post_content'  => '这是一个测试文章。',
  'post_status'   => 'publish',
  'post_author'   => 1,      //对应作者 ID
  'post_category' => array(4)   //对应文章分类
);
// 插入文章到数据库
wp_insert_post( $my_post );
?>

参考 https://blog.csdn.net/sam_zhang1984/article/details/51159252

猜你喜欢

转载自blog.csdn.net/james_laughing/article/details/88928745