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
wp_insert_post( $my_post, $wp_error );
I think this must create only one page.
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.