wp_delete_post CHANGING TO wp_update_post

Discussion in 'PHP' started by VeAn, Oct 16, 2008.

  1. #1
    Hy,

    I install Antropos plugin and need one change. Author of plugin is not replying to comments on his blog so I need help from someone with more knowledge in php then I have. :)

    This function I need to change:

    function atropos_delete_expired_posts () {
      global $wpdb;
      $result = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_atropos_expiration_date' AND meta_value < '" . date("Y/m/d") . "'");
      foreach ($result as $a) {
        wp_delete_post ($a->post_id);  //THIS LINE NEED TO BE CHANGED
      }
    Code (markup):
    Change it to just change post status from "publish" to "pending". I do not want to delete those posts.

    I was thinking something like this but that isn't working:

    function atropos_delete_expired_posts () {
      global $wpdb;
      $result = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_atropos_expiration_date' AND meta_value < '" . date("Y/m/d") . "'");
      foreach ($result as $a) {
    
     //I PUT NEXT 4 LINES INSTEAD
           $my_post = array();
           $my_post['ID'] = $a;
           $my_post['post_status'] = 'pending';
           wp_update_post( $my_post );
      }
    Code (markup):

    I also find on web some other code but I don't know if I need it:
    $mysql_query('UPDATE wp_posts SET post_status = "pending", WHERE ID = "'.$a['ID'].'"');
    Code (markup):
    I think my problem is that I don't know how to implement code correctly so, if You have any idea I would be grateful.

    Thanks!

    Andrija
     
    VeAn, Oct 16, 2008 IP
  2. VeAn

    VeAn Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't know if this goes to some other category but I'm sure it have something with php.

    I know just basics of php what I have learned in last few years using wordpress and know almost nothing about db.

    Please, anyone?
     
    VeAn, Oct 16, 2008 IP