插入WordPress的帖子通过PHP致命错误
当我想使用wp_insert_post($ my_post);函数我得到以下错误:插入WordPress的帖子通过PHP致命错误
Fatal error: Cannot redeclare create_initial_post_types() (previously declared in /home/izradawe/public_html/mydomain.com/wp-includes/post.php:20) in /home/izradawe/public_html/mydomain.com/wp-includes/post.php on line 152
你能帮我这个吗?我使用
代码:
include_once('../wp-load.php');
include("../wp-includes/post.php");
// Creating post
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => 5,
'post_type' => 'post'
);
// Insert the post into the database
wp_insert_post($my_post);
为了获取WordPress的主要功能,请尝试:
<?php
include '../wp-blog-header.php';
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => 5,
'post_type' => 'post'
);
wp_insert_post($my_post);
?>
非常感谢你:) –
随时,亲爱的。 – maiorano84
如果你写里面的single.php或index.php文件或模板目录内的任何模板文件不需要包含文件WP-load.php或交的代码。 PHP
我不在single.php或index.html中编写代码,我正在编写一个单独的管理面板,我试图做。 –
在wordpress模板目录中创建一个带有代码wp_insert_post函数的模板页面,并将所有参数传递给该页面 –
我将该页面放在WordPress模板文件夹中,但我得到了相同的致命错误。 –
变化 “包括” 到 “include_once”
你用什么类型的文件来包含它?它是一个主题还是一个插件?无论如何,你做错了什么 – janw
我想创建单独的“管理面板”,其中有人可以添加新的帖子到我的WordPress站点,我知道这是错的,因为我在寻求帮助。 –
所以你正在创建一个完全独立于'/ wp-admin'的后端? – janw