Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
     }
 }
share|improve this question

1 Answer 1

up vote 0 down vote accepted

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');
        }
 }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.