0

I have a function that expires posts on a date, and adds a check to the database. Now, I'd like the ability to "recycle" those posts with new expiration date, but in order to do this, I need to erase the _expiration_date_processed entry. Is the function below the best way to achieve this, especially in the case where there is a status change for multiple posts using quick edit? Thank you for any insights.

add_action('draft_to_published','gcpl_draft_to_published');
 function gcpl_draft_to_published($post){
  global $post;
  global $wpdb;
     $current_id = $post->ID;
     $processsql = 'select meta_value from '.$wpdb->postmeta.' where meta_key = "_expiration-date-processed" AND post_id = '.$current_id.'';
     $processresult = $wpdb->get_col($processsql);
      if (!empty($processresult)) foreach ($current_id as $a) {
       delete_post_meta($a->post_id, '_expiration-date-processed');
     }
 }

1 Answer 1

0

Nevermind, I was complicating this whole process because I wasn't thinking about just using get_post_meta().

add_action('draft_to_publish','gcpl_draft_to_published');
 function gcpl_draft_to_published($post){
      $exp_processed = get_post_meta($post->ID, '_expiration-date-processed', true);
    // check if the custom field has a value
        if($exp_processed != '') {
          delete_post_meta($post->ID, '_expiration-date-processed');
        }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.