2013-05-19 57 views
0

我在我的根wordpress文件夾中有一個名爲wp_insert_post.php的文件中有以下代碼 但是,當我從瀏覽器運行此URL時,我只是得到一個空白頁。沒有任何回聲語句出現。我究竟做錯了什麼? 在此先感謝!WordPress的wp_insert_post功能不工作

<?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"; 
?> 
+0

在你的error_log裏有什麼東西嗎? – Achrome

+0

數組語法錯誤。數組應該是$ post = array('menu_order'=> 0,'page_template'=> null .... –

+0

是的,這是問題,謝謝! – Dave

回答

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); 

所以,取出[]和陣列中的每個參數之後添加逗號,

相關問題