Title: WillPac's Replies | WordPress.org

---

# WillPac

  [  ](https://wordpress.org/support/users/willpac/)

 *   [Profile](https://wordpress.org/support/users/willpac/)
 *   [Topics Started](https://wordpress.org/support/users/willpac/topics/)
 *   [Replies Created](https://wordpress.org/support/users/willpac/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/willpac/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/willpac/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/willpac/engagements/)
 *   [Favorites](https://wordpress.org/support/users/willpac/favorites/)

 Search replies:

## Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Schedule Post Changes With PublishPress Future: Unpublish, Delete, Change Status, Trash, Change Categories] Post Expiry based on custom field [Solution!]](https://wordpress.org/support/topic/post-expiry-based-on-custom-field-solution/)
 *  [WillPac](https://wordpress.org/support/users/willpac/)
 * (@willpac)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/post-expiry-based-on-custom-field-solution/#post-5118417)
 * In case if anyone is scouring the internet looking for a solution to use this
   plugin with Gravity Forms, here is the solution I crafted. Thanks for the ‘codespiration’
   slickorange!
 *     ```
       function after_gig_submit($entry){
       	$post_id = $entry["post_id"];
   
       	$date = get_post_meta( $post_id, 'Date', true );
   
       	set_expiration($post_id, $date);
       }
   
       function set_expiration($id, $date) {
   
       	// 'm/d/Y' is the format of my GF date field
           $formatted_date = DateTime::createFromFormat('m/d/Y', $date);
   
           $month	 = intval($formatted_date->format('m'));
           $day 	 = intval($formatted_date->format('d'));
           $year 	 = intval($formatted_date->format('y'));
   
       	//Manually set post to expire at the end of the day.
           $hour 	 = 23;
           $minute  = 59;
   
           $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
   
       	$opts = array(
       		'expireType' => 'draft',
       		'id' => $id
       	);
   
           _scheduleExpiratorEvent($id, $ts, $opts);
       }
   
       //Add the action hooks for each form that can post gigs
       add_action('gform_after_submission_1', 'after_gig_submit', 1);
       add_action('gform_after_submission_4', 'after_gig_submit', 1);
       add_action('gform_after_submission_5', 'after_gig_submit', 1);
       ```
   
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Schedule Post Changes With PublishPress Future: Unpublish, Delete, Change Status, Trash, Change Categories] Post Expiry based on custom field [Solution!]](https://wordpress.org/support/topic/post-expiry-based-on-custom-field-solution/)
 *  [WillPac](https://wordpress.org/support/users/willpac/)
 * (@willpac)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/post-expiry-based-on-custom-field-solution/#post-5118361)
 * Slickorange, thank you so much for posting this! I’m trying to do a similar thing,
   and I was wondering if you had any ideas of how to modify your code to get it
   to work for my case.
 * My posts are created through Gravity Forms, and thus have custom fields made 
   by GF. I currently have a custom field titled ‘Date’ in the format of mm/dd/yyyy.
   I’m trying to set the expiration date based on this field. Any chance in the 
   kindness of the heart you can try to help? Currently this code is not working
   at all–I’m new to developing in WordPress so I’m sure I’m missing something important
   here.
 *     ```
       //My attempt at dynamically setting the expiration date of posts
       //Here we go...let's see what we can make happen here
       function set_expiration($post_id) {
       	//Remove the default expiration date
       	remove_action('save_post', 'expirationdate_update_post_meta');
       	//Pull the date we need
       	$date = get_post_meta( $post_id , 'Date', true );
   
       	expirationdate_update_post_meta_gig($post_id, $date);
       }
   
       function expirationdate_update_post_meta_gig($id, $date) {
           // don't run the echo if this is an auto save
   
           if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
               return;
           } else {
           //'m/d/Y' is the format my ACF date field is outputting - can be differ from each setup!
               $formatted_date = DateTime::createFromFormat('m/d/Y', $date);
   
               $month	 = intval($formatted_date->format('m'));
               $day 	 = intval($formatted_date->format('d'));
               $year 	 = intval($formatted_date->format('y'));
   
               //I am not using time in my ACF field, so I am setting it manually to the end of the day.
               $hour 	 = 23;
               $minute  = 59;
   
               $opts = array();
               $ts = get_gmt_from_date("$year-$month-$day $hour:$minute:0",'U');
   
               // Schedule/Update Expiration
               $opts['expireType'] = 'draft';
               $opts['id'] = $id;
   
               _scheduleExpiratorEvent($id,$ts,$opts);
       	}
       }
   
       add_action('gform_after_submission_1', 'set_expiration', 1);
       add_action('gform_after_submission_4', 'set_expiration', 1);
       add_action('gform_after_submission_5', 'set_expiration', 1);
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)