• 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 CHANGE
      }

    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 );
      }

    I also find on web some other code:
    $mysql_query('UPDATE wp_posts SET post_status = "pending", WHERE ID = "'.$a['ID'].'"');

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter vean

    (@vean)

    Anyone?

    Please…

    Try this out:

    foreach ($result as $a) {
    
        //wp_delete_post ($a->post_id);
    
        $my_post = array();
        $my_post['ID'] = $a->post_id;
        $my_post['post_status'] = 'draft';
    
        // Update the post into the database
        wp_update_post( $my_post );
    }
    Thread Starter vean

    (@vean)

    Hy,
    I wasn’t online last few days. Have some offline job. 🙂

    Just want to thank You Kolucciy. It is working great.
    Also, if someone want to allow using Antropos just for ADMINS:

    Replace:

    function atropos_add_box () {
      add_meta_box('atropos', __('Expiration Date'), 'atropos_custom_meta_box', 'post', 'advanced', 'high');
    }

    With THIS:

    function atropos_add_box () {
    	get_currentuserinfo() ;
    	global $user_level;
    	if ($user_level > 9) {
      add_meta_box('atropos', __('Expiration Date'), 'atropos_custom_meta_box', 'post', 'advanced', 'high');
    }}

    excellent

    Thanks kolucciy, vean

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_delete_post change TO post_status_update’ is closed to new replies.