1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trouble with WordPress "wp_insert_post()" function

Discussion in 'PHP & Perl' started by maribge, Nov 2, 2009.

  1. maribge

    maribge Junior Member

    Joined:
    May 6, 2007
    Messages:
    106
    Likes Received:
    11
    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?
     
  2. showboytridin

    showboytridin Regular Member

    Joined:
    Sep 5, 2009
    Messages:
    348
    Likes Received:
    714
    Location:
    127.0.0.1
    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.
     
  3. showboytridin

    showboytridin Regular Member

    Joined:
    Sep 5, 2009
    Messages:
    348
    Likes Received:
    714
    Location:
    127.0.0.1
    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.
     
  4. maribge

    maribge Junior Member

    Joined:
    May 6, 2007
    Messages:
    106
    Likes Received:
    11
    Is there a way to switch off this back up function so I don't have to remove duplicate posts later?
     
  5. showboytridin

    showboytridin Regular Member

    Joined:
    Sep 5, 2009
    Messages:
    348
    Likes Received:
    714
    Location:
    127.0.0.1
    Only if you change the source code on the PHP files. I don 't think that a function for that exists.
     
  6. Scripteen

    Scripteen Elite Member

    Joined:
    Sep 19, 2009
    Messages:
    1,811
    Likes Received:
    1,918
    Home Page:
    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.