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

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$post_data = array(
'post_title' => '新的文章',
'post_content' => '这是一篇新的文章。',
'post_status' => 'publish', // 设置为 'publish' 以立即发布文章
'post_type' => 'post', // 也可以设置为 'page' 或其他自定义的文章类型
);
$post_id = wp_insert_post($post_data);
$post_data = array( 'post_title' => '新的文章', 'post_content' => '这是一篇新的文章。', 'post_status' => 'publish', // 设置为 'publish' 以立即发布文章 'post_type' => 'post', // 也可以设置为 'page' 或其他自定义的文章类型 ); $post_id = wp_insert_post($post_data);
$post_data = array(  
    'post_title' => '新的文章',  
    'post_content' => '这是一篇新的文章。',  
    'post_status' => 'publish', // 设置为 'publish' 以立即发布文章  
    'post_type' => 'post', // 也可以设置为 'page' 或其他自定义的文章类型  
);  
$post_id = wp_insert_post($post_data);

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

未能解决您的问题?

请提交 联系工单