Wordpress wp_insert_post 功能不起作用 [英] Wordpress wp_insert_post function not working
本文介绍了Wordpress wp_insert_post 功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 wordpress 根文件夹中的一个名为 wp_insert_post.php 的文件中有以下代码但是,当我从浏览器运行这个 url 时,我只会得到一个空白页面.没有出现 echo 语句.我究竟做错了什么?提前致谢!
I have the following code in my root wordpress folder in a file called wp_insert_post.php However when I run this url from the browser I just get a blank page. None of the echo statements appear. What am I doing wrong? Thanks in advance!
<?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";
?>
推荐答案
你的格式不好.像这样尝试(取自 codex )
Your format is not good. Try it like this ( taken from the 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 );
因此,删除 [
和 ]
并在数组中的每个参数后添加逗号 ,
.
So, remove the [
and ]
and add commas ,
after each parameter in the array.
这篇关于Wordpress wp_insert_post 功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文