Trouble with WordPress "wp_insert_post()" function

maribge

Junior Member
Joined
May 6, 2007
Messages
106
Reaction score
22
Hello,

I have an issue with wp_insert_post() function on 2.8.5 version (haven't

worked with wordpress before that). The function makes two duplicate

records in the database instead of one. Here is the code snippet:

Code:
$post['post_title'] = "test3";
$post['post_content'] = "another test3";
$post['post_status'] = 'publish';
$post['post_author'] = 1;
$post['post_category'] = array(0);
$post['post_date'] = "2009-10-01 01:01:01";
$post['post_date_gmt'] = "2009-10-01 01:01:01";

$post = add_magic_quotes($post);
$postID = wp_insert_post($post);
I've been trying to figure out what the problem might be. I tried to

intercept the values of the "$query" variable in wp-includes/wp-db.php

file on 678 line and got an SQL query, which posts to the database:


Code:
INSERT INTO `wp_posts` 

(`post_author`,`post_date`,`post_date_gmt`,`post_content`,`post_content_

filtered`,`post_title`,`post_excerpt`,`post_status`,`post_type`,`comment

_status`,`ping_status`,`post_password`,`post_name`,`to_ping`,`pinged`,`p

ost_modified`,`post_modified_gmt`,`post_parent`,`menu_order`,`guid`) 

VALUES ('1','2009-10-01 01:01:01','2009-10-01 01:01:01','toje 

test3','','test3','','publish','post','open','open','','test3','','','20

09-10-01 01:01:01','2009-10-01 01:01:01','0','0','')

This query appears in the variable only once, as it should, yet each

time wp_insert_post() makes two duplicate records instead of one, which

leads me to a conclusion that another SQL query runs somewhere else.

Can someone help me?
 
Yes, it can be a backup. That 's kind normal when using wordpress. Keep the code and remove the content you don 't need later. There are plenty of tutorials on how to do that.
 
Yes, it can be a backup. That 's kind normal when using wordpress. Keep the code and remove the content you don 't need later. There are plenty of tutorials on how to do that.
 
Is there a way to switch off this back up function so I don't have to remove duplicate posts later?
 
Only if you change the source code on the PHP files. I don 't think that a function for that exists.
 
Is there a way to switch off this back up function so I don't have to remove duplicate posts later?

You can add a 2nd query to remove posts with the same time right after executing your main query. But that would be a strong one if you have too many posts in the database.

not the best solution but just something that should work.
 
Back
Top