通过php插入wordpress帖子致命错误

通过php插入wordpress帖子致命错误,wordpress,post,Wordpress,Post,当我想使用wp\u insert\u post($my\u post)时函数我得到以下错误: 致命错误:无法重新声明创建\初始\后期\类型() 声明于 /home/izradawe/public_html/mydomain.com/wp includes/post.php:20)中 /home/izradawe/public_html/mydomain.com/wp-includes/post.php在线 152 你能帮我吗 我使用的代码: include_once('../wp-load.

当我想使用wp\u insert\u post($my\u post)时函数我得到以下错误:

致命错误:无法重新声明创建\初始\后期\类型() 声明于 /home/izradawe/public_html/mydomain.com/wp includes/post.php:20)中 /home/izradawe/public_html/mydomain.com/wp-includes/post.php在线 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 );

如果您在single.php或index.php中编写代码,或在template目录中编写任何模板文件,则无需包含wp-load.php或post.php文件,即可访问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 );
?>


包含
更改为
包含
一次

您使用什么类型的文件包含此内容?它是一个主题还是一个插件?不管怎么说,你做错了什么我想创建一个单独的“管理面板”,有人可以在其中向我的wordpress站点添加新帖子,我知道这是错误的,因为我在寻求帮助。所以你创建的后端完全独立于
/wp admin
?是的,在complety separate后端中,我创建了一个表单,管理员可以使用该表单创建一篇新文章,我想使用函数wp_insert_post($my_post)创建一篇新文章,但它抛出了上述错误。我没有在single.php或index.html中编写代码,我在一个单独的管理面板中写作,我正在尝试制作。在wordpress模板目录中创建一个带有代码wp_insert_post函数的模板页面,并将所有参数传递到该页面。我将该php页面放入wordpress模板文件夹,但我遇到了同样的致命错误。创建一个模板页面并将代码放在此处是指: