Title: Add expiration date programmatically
Last modified: August 31, 2016

---

# Add expiration date programmatically

 *  [vespino](https://wordpress.org/support/users/vespino/)
 * (@vespino)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/)
 * I’m insertings posts via een custom script and I’m looking for a way of addding
   the expiration date. Is this already implemented?
 * [https://wordpress.org/plugins/post-expirator/](https://wordpress.org/plugins/post-expirator/)

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

 *  [Daniyal Ahmed (a11n)](https://wordpress.org/support/users/daniyalahmedk/)
 * (@daniyalahmedk)
 * [10 years ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-7339866)
 * I am also interested in this question, is there any quick solution for it?
 *  [kilinkis](https://wordpress.org/support/users/kilinkis/)
 * (@kilinkis)
 * [10 years ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-7339873)
 * im also interested in this
 * I’ve trying to add an epoch value to _expiration-date,
    this string ‘s:52:”a:
   2:{s:10:”expireType”;s:5:”draft”;s:2:”id”;i:3932;}”;’ for _expiration-date-options
   and ‘saved’ at _expiration-date-status
 * note that the string hast the post id, so that’s not OK for all posts, you have
   to replace that
 * this is still not working 🙁
 *  [kilinkis](https://wordpress.org/support/users/kilinkis/)
 * (@kilinkis)
 * [10 years ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-7339874)
 * for example:
    the value stored in _expiration-date post meta field is: 1464270120000
   which is GMT: Thu, 26 May 2016 13:42:00 GMT
 * but when I check on the plugin box, it shows the post expires on Nov. 15th 2016
   at 17:00.
 * very weird
 *  [kilinkis](https://wordpress.org/support/users/kilinkis/)
 * (@kilinkis)
 * [10 years ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-7339876)
 * well I got it to work guys, I was very close
    here it goes:
 * the time stamp should be in seconds, not miliseconds
    so trim the last three 
   characters of it
 * in a previous comment I had this timestamp: 1464270120000
    but the correct one
   was 1464270120
 * 😉
 * now, while you have the plugin installed, you can use this function:
    _scheduleExpiratorEvent(
   $post_id,$ts,$opts);
 * in case you want to see it’s code, head to the file post-expirator.php file on
   the root of the plugin directory.
 * last but not least, $opts, should be an array, in my case I formatted it like
   this:
    $opts = array(); $opts[‘expireType’] = ‘draft’; $opts[‘id’] = $post_id;
 * and that should do it!
 *  [hs1972](https://wordpress.org/support/users/hs1972/)
 * (@hs1972)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-7339886)
 * Hi [@kilinkis](https://wordpress.org/support/users/kilinkis/). Thanks for sharing.
   I’m using WP All Import and can import the right date using the Unix timestamp
   as you describe. However, they don’t expire (everything is working when I add
   a post manually they expire then, just not if I add posts by importing).
 * I think this is because there’s nothing in the _expiration-date-options field.
   I’m not sure how to import this when it’s in the a:2:{s:10:”expireType”;s:5:”
   draft”;s:2:”id”;i:12345;} format because I don’t know what the id will be at 
   the time of importing.
 * Do you know what would be the best way around this? I’m fairly new to this so
   working things out as I go along but this one is baffling me.
 * Do I need to edit the code in the plugin? I can see the following in there:
 * $opts = array();
    $ts = get_gmt_from_date(“$year-$month-$day $hour:$minute:0”,’
   U’);
 * // Schedule/Update Expiration
    $opts[‘expireType’] = $_POST[‘expirationdate_expiretype’];
   $opts[‘id’] = $id;
 * I can also see function _scheduleExpiratorEvent($id,$ts,$opts) a little further
   down.
 * I presume I would change the code that you mentioned in the Schedule/Update Expiration
   section? If this is the case, do you know what I would need to put under the 
   _expiration-date-options column when I’m importing? Anything at all or would 
   this be catered for automatically with the edited code?
 * Many thanks in advance to anyone that can help.
 *  [jattard](https://wordpress.org/support/users/jattard/)
 * (@jattard)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-8484321)
 * Hi [@hs1972](https://wordpress.org/support/users/hs1972/),
 * I am using wp all import too and I have your same issue. Have you managed to 
   find a solution?

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

The topic ‘Add expiration date programmatically’ is closed to new replies.

 * ![](https://ps.w.org/post-expirator/assets/icon-256x256.png?rev=3118683)
 * [Schedule Post Changes With PublishPress Future: Unpublish, Delete, Change Status, Trash, Change Categories](https://wordpress.org/plugins/post-expirator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-expirator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-expirator/)
 * [Active Topics](https://wordpress.org/support/plugin/post-expirator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-expirator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-expirator/reviews/)

 * 6 replies
 * 5 participants
 * Last reply from: [jattard](https://wordpress.org/support/users/jattard/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/add-expiration-date-programmatically/#post-8484321)
 * Status: not resolved