0

当我想使用wp_insert_post( $my_post ); 函数我收到以下错误:

致命错误:无法在 /home/izradawe/public_html/mydomain.com/wp-includes/post 中重新声明 create_initial_post_types()(之前在 /home/izradawe/public_html/mydomain.com/wp-includes/post.php:20 中声明) .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 );
4

3 回答 3

2

要访问 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 );
?>
于 2012-05-03T16:49:16.870 回答
0

如果您在 single.php 或 index.php 或模板目录中的任何模板文件中编写代码,则无需包含文件 wp-load.php 或 post.php

于 2012-05-03T10:57:11.873 回答
-1

更改includeinclude_once.

于 2013-09-05T07:43:03.237 回答