wp_insert_post(), creates two pages?

I am new to wordpress. I want to create a new page in wordpress by using this. It is working but it creates two pages. Can any one help me to fix this problem .

    $my_post = array(
  'post_title'    => 'profile',
  'post_status'   => 'publish',
  'post_type'     => 'page',
  'post_author'   => 1
  );enter code here

Insert the post into the database

Read More
wp_insert_post( $my_post, $wp_error );

I think this must create only one page.

Related posts

Leave a Reply

2 comments

  1. I got a similar error before, when i am running a custom php script to insert posts into the WordPress database, using the wp_insert_post statement. Weirdly it created 2 records in wp_posts table for every post.

    Not sure what is the issue, but i realized that when i ran the php code in the same browser where i am logged in as administrator, i got this duplicate posts issue. I resolved it by running my custom php code in a separate browser.

    So make sure that you are running your custom php code with SQL query in a browser, that has no WordPress login in it. Hope it helps someone.

  2. I had a similar issue, I wanted to create a custom Template page with a functionality to add a post,but by default the header and the footer has the loop for getting all the posts, and I think so that loop were creating two posts, because my page was not requiring the begin post loop, i just removed all of them and just had my own custom function to insert the post, it worked for me.