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

时间:2012-05-03 10:37:49

标签: wordpress post

当我想使用 wp_insert_post($ my_post); 功能时,我收到以下错误:

  

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

3 个答案:

答案 0 :(得分: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 );
?>

答案 1 :(得分:0)

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

答案 2 :(得分:-1)

将“include”更改为“include_once”