WordPress.org

Ready to get started?Download WordPress

Forums

wp_delete_post change TO post_status_update (5 posts)

  1. vean
    Member
    Posted 5 years ago #

    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

  2. vean
    Member
    Posted 5 years ago #

    Anyone?

    Please...

  3. kolucciy
    Member
    Posted 5 years ago #

    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 );
    }
  4. vean
    Member
    Posted 5 years ago #

    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');
    }}
  5. systematic
    Member
    Posted 5 years ago #

    excellent

    Thanks kolucciy, vean

Topic Closed

This topic has been closed to new replies.

About this Topic