Reputation: 777
When I want to use wp_insert_post( $my_post ); function i get the following error:
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
Can you help me with this?
Code which I using:
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 );
Upvotes: 0
Views: 1487
Reputation: 11980
In order to gain access to Wordpress' main functions, try:
<?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 );
?>
Upvotes: 2
Reputation: 9
If you writing the code inside single.php or index.php or any template file inside template directory no need to include the file wp-load.php or post.php
Upvotes: 0