Wordpress wp_insert_post功能不起作用

时间:2013-05-19 12:13:11

标签: php wordpress

我的root wordpress文件夹中有以下代码,名为wp_insert_post.php 但是,当我从浏览器运行此URL时,我只得到一个空白页面。没有出现任何echo语句。我究竟做错了什么? 提前谢谢!

<?php
require_once('wp-config.php');
error_reporting(E_ALL);
ini_set('display_errors',1);
echo "done1";

$post = array(
  'ID' => [] 
  'menu_order' => ['0'] 
  'page_template' => [] 
  'comment_status' => ['closed'] 
  'ping_status' => ['open']
  'pinged' => [] //?
  'post_author' => ['1'] 
  'post_category' => []
  'post_content' => ['testautopage123']
  'post_date' => ['2013-05-18 18:39:33'] 
  'post_date_gmt' => ['2013-05-18 18:39:33']
  'post_excerpt' => []
  'post_name' => ['test-auto-page']
  'post_parent' => [] 
  'post_password' => []
  'post_status' => ['publish']
  'post_title' => ['Test Page']
  'post_type' => ['page']
  'tags_input' => []
  'to_ping' => []); 
echo "done2";
// Insert the post into the database
wp_insert_post($post);
echo "done3";
?>

1 个答案:

答案 0 :(得分:2)

你的格式不好。试试这样(取自codex

$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );

因此,请移除[],并在数组中的每个参数后添加逗号,

相关问题