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.

Answers


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.


Need Your Help

GOOGLE Place Api: how to add more place names against single place by google place actions

google-maps google-places-api

How to add one place name as a primary in English and then different names on different languages for same place by Google place actions. It could be primary or not primary on different languages.

Java download any page - including 404, error-message pages?

java inputstream urlconnection bufferedinputstream

I've used URLconnection.connect and BufferedInputStream(connection.getInputStream()) to download pages, but unfortunately it seems it is unable to download any 404 pages or any other error-message ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.