WordPress Auto Post Expire Plugin
The free WordPress Auto Post Expire from Electric Studio plugin allows you to set a expiry date on a post. At the set date, the post will change status into a draft and no longer display on your site.
The administration panel for this plugin that allows you to choose which post type (including custom post types) you would like to the plugin to be available on.
The Auto Post Expire plugin is great when you have posts about events, offers or other time sensitive information that needs to be automatically removed from your website.
If you want to show a date on the front-end of your site, you can use the shortcode of [expirydate format="m-d-Y"] (The format part is optional).
Developer Note: Instead of using a shortcode you can use function `esape_get_expiry_date($dateFormat = “d-M-Y”);`.
You can download the plugin at the official WordPress site.
Update: Good news, everyone!
So 1.4 of the plugin was reported broken by a number of people, so I went ahead and rewrote the whole thing to make it work nice with 3.4.2. I removed code that was using direct SQL through the database global object (if this doesn’t mean anything to you, worry not :) ). Here’s a short run-down of what happened to it, how to use, possible pitfalls, etc.
Stuff changed
jQuery and jQuery UI
Version 1.4 pulled in external scripts. This was changed in 1.5, so it is using the scripts shipped with WordPress itself. Makes code leaner, and less likely to break, plus, as you update WordPress, the scripts will get better as well.
Time
Not just date. Beforehand you set a day to expire posts. That meant that one minute after 11:59pm of the previous day, the post would disappear. What if you wanted it to expire midday? Also this data is now stored as a timestamp, which basically every known programming language understands and can produce a dateformat of your choosing. More on this later.
FAQ & Howtos
Is it going to save my preferences from 1.4?
Yes, all the options / expiry dates should carry over to 1.5 no problem.
Can I display the expiry date in the post, or in the code?
Yes. The shortcode [expirydate] is there, or you can use es_ape_exp_date() function for that in your code.
What about customizing the dateformat?
The full reference for both the shortcode and the function is below:
[expirydate format="d-M-Y"]
The default is “d-M-Y”. You can replace that with anything that is a valid php date() syntax. So if you only want the year, you would use [expirydate format="Y"], if you want to add the time as well, use [expirydate format="d-M-Y G:i"]
es_ape_exp_date( $format, $echo );
$format (string) is the same format used by the shortcode. Default is “d-M-Y”.
$echo (bool) is either true or false. True echoes the date, false returns it.
I want to get the timestamp itself, but es_ape_exp_date() will only give me a formatted date!
Fear not, for that isn’t that hard. Use this (assuming you are within The Loop):
$timestamp = get_post_meta( get_the_ID(), "es_ape_expiry", true );
You can then manipulate it however you like. Substract a week, and show an additional message if it’s going to expire soon ( “Hurry, offer ends soon!” ), or something like that. This is in seconds, so a week would be 7*24*60*60 = 604800 seconds.
Can I order the posts by expiry date (soonest to expire comes first, for example)?
Yes. Use this:
$args = array(
'post_status' => 'publish',
'meta_key' => 'es_ape_expiry',
'order' => 'ASC',
'orderby' => 'meta_key_num'
);
$ordered_posts = new WP_Query( $args );
if( $ordered_posts->have_posts() ) {
while( $ordered_posts->have_posts() ) {
$ordered_posts->the_post();
# your code here ....
}
} else {
echo "No posts found";
}
Possible pitfalls
As I inherited the previous developer’s code, and decided the best course of action is to understand what it does, and rewrite it using the WordPress way ( “there’s a function for that” ), there might be instances where previously solved problems would crop up again.
For support, check out the plugin’s wordpress support page.

I found your plugin and it would be a perfect solution to an issue I currently have with stories that need to expire on a certain date and time. Unfortunately, it appears not to work. Are you still offering assistance with this plugin?
Hello, it’s not compatible with latest version of WordPress, and unfortunately we haven’t had time to fix it yet :-/
I’m running Version 1.6.8 on WP 3.5 and posts are not expiring. It did work, but now appears not to work. Are there still known issues? No errors, it’s just the post no longer expires.
Thanks
Hello, did it work on the same WordPress version or did it stop working after an upgrade?
Yes, I did update. That’s just it, there are no errors. It’s just not working. My posts are not expiring. For example, this post
http://mckenziepta.com/2012/check-the-lost-found-before-winter-break/
was set to expire on Jan 1. But it’s still there.
I can tell you at one point, I upgraded this plugin and it expired all of my posts, even the one without expiry dates. I turned it off at that point. And I then I turned it on again after an update. That might have been when it stopped working, but I can’t be sure.
After working wonderfully for a year and a half, this plugin stopped working for me about 3 or 4 months ago. (I haven’t had time before now to look into why.) I’m running the latest version of the plugin and the latest version of WordPress. I’m not sure how to troubleshoot this since I’m not sure what caused it to stop working. I’d appreciate any thoughts on the matter.
Hi, did you update yo to the latest version last week? It’s also very hard to help if you don’t tell us what is going wrong, eg error messages, missing functions etc.
Plugin was functioning properly, but after recent updates, Expirations are no longer taking effect. I just moved to WP3.5 (and am using v1.6.6 of A.P. Expire)… any known incompatibilities with the latest version of WordPress? Just had a client have someone printout a couple pages of expired coupons and demand they fulfill them. :-/
Thanks for any advice in advance!
Steve C. – 3Cstudio
HI Steve
We have just purged an update to WordPress that should fix this, please let me know how you get on.
How to display the expiration date in thesis theme.i mean how to use function in thesis custom function.
Hi, it’s not built for or tested in Thesis. If the shortcode [expirydate] or function esape_get_expiry_date() doesn’t work, then you would have to put your thinking cap on I’m afraid.
its seems that the post does get expired, meaning that the posts remain as published! any help?
Hi, you mean that they do NOT get expired? What version of WordPress are you on?
Hi,
Is there a way on a category page to order the posts by expiry date? …With the soonest expiry date at the top?
Hi Ken, not out of the box, you would need to create a custom query for that.
Hello, thanks so much for the plugin im trying to add the functionality of this plugin to a ‘user submitted posts’ plugin. adding a box to the form which allows a user to select a date which ends their uploaded posts. Any ideas? thanks for the help
Hugo,
If you are adding posts from the front-end, to add an expiry field, you just need to add the field so that it stores the date in YYYY-MM-DD and is stored as post-meta called ‘_es_expirydate’
I hope this points you in the right direction.
Regards,
James
Hello James,
thanks for update, quick response, and a very handy plugin, all working well.
Sorry James, I keep getting [Delivery Status Notification (Failure]. Could you email me so I can reply.
Mark
Hi Mark. That looks more like an email/server side issue than an issue with the plugin. Have you checked your server log at all?
James
sorry
console tab
Please do send me a screenshot, as my firebug isn’t showing any errors. My email is james[at]electrictricstudio[dot]com
Hello James,
using firebug consul tab shows an error, can I email you a screen print of the firebug report.
I’m a bit out of my depth now
Mark
James,
sorry for my tardy reply.
I had updated your plugin, and then tried to upload photos to a new gallery on my site. That went fine, except NGG wouldn’t creat thumbnails as it usually does. I checked my NGG options page & noticed it’s layout had changed from tabs to a list style.
I searched Google & found suggestions this was often a conflict with another plugin. I then disabled my plugins one by one & established that it was the updated version of ESAPE.
I have just repeated the process(updated ESAPE) with the same results.
I also noticed that that in the WP admin page the dropdown arrows in the boxes on the left of the page(eg Appearance, Pages etc) wouldn’t work.
I have no knowledge of coding but think I have read that this type of function where more information is displayed without refreshing the page is enabled using AJAX, as would the tabs in NGG options page.
I couldn’t see any errors in the display of pages in firefox when the new version was installed.
I read that firebug can used to show JS errors but haven’t figured out how to do this. More reading.
Thanks
Mark
I installed the latest update & it breaks functions in nexgen gallery plugin. Deactivate ESAP & NGG works again. It stops NGG creating thumbnails & breaks ‘Options’ (NGG) page layout from tabs to list form.
This is a very handy plugin. I have reverted to the older version & there is no conflict with it.
I hope there is a fix for this
Thanks
M
Mark,
I have install nextgen gallery on my dev version of WordPress and it seems to work fine for me. Could you please tell me if you get any errors when the post expiry plugin is enabled?
Also, what exactly breaks when the plugin is activated?
Regards,
James
Is there a code I can use to allow the viewer to select the expiration date from the front end as all of my posts are published by users via the front end.
Thank you for such a great plugin.
Randolph,
The post expiry dates are set as post meta, i.e. to get a post’s expiry date, use <code>get_post_meta($post->ID,"_es_expirydate",true)</code>.
If you are not familiar with updating/editing/removing post meta, please see <a href="http://codex.wordpress.org/Function_Reference/post_meta_Function_Examples" target="_blank">http://codex.wordpress.org/Function_Reference/post_meta_Function_Examples</a>.
Regards,
James
Is there any way to have this plugin also be accessible through the Quick Edit screen of a post as well?
Unfortunatly, despite being a great idea, it is not in out current road map. However, we would like to add this feature in the future if we get the time.
Is there a way to set all posts or at least all of certain categories to auto expire? My blog has hundreds of posts, some of which are fed in by an rss feed, but it deals with time sensitive information and it is tedious to go into each post and set the expiration date.
Unfortunately, with out doing some mysql yourself that isn’t possible.
which is literally just looked like this feature included in the file function
<?php
$date = get_post_meta($post->ID,"_es_expirydate",true);
$data = mysql2date(get_option(‘date_format’),$date );
echo $data;
?>
I have set expiry dates for my posts and the plug-in works great, but is there a way I could publish the expiry date in the post itself for viewers?
and thank you for a great and very useful plug-in!
I plan on adding some shortcode to do this in the next plugin.
However for now (as pointed out by Tomasz) you can use the following PHP:
<code><?php
$date = get_post_meta($post->ID,"_es_expirydate",true);
$data = mysql2date(get_option(‘date_format’),$date );
echo $data;
?></code>
Firstly, thank you for the plugin. Just wondered if I can reformat the date output to dd/mm/yyyy please.
Can’t seem to find it anywhere
The plugin stores the value as yyyy-mm-dd as that is the mysql format. In a later version I would like to allow to format to be changed. If you are outputting the expiry date in your post template, you would need to change the format using the php date function (http://php.net/manual/en/function.date.php).
Hey there,
Is there a way to set the expired posts to auto-delete instead of being saved as a draft?
Thanks.
Jason, thanks for the suggestion. I will look into adding this in a near-future version.
Hi, great plugin. Thanks! Only one question. Is there a way to output in my theme the expiration date of the post? That would be a great feature.
Thanks from Argentina.
Hey, I’m glad you enjoy the plugin. To output to expiration date on a post, use:
< ?php echo get_post_meta($post->ID,"_es_expirydate",true); ?>I hope this helps. :-)
Does the post expire at midnight on the date that you set?
Thanks!
Hi Sue
Yes, that is correct. When the site is loaded, it makes sure non of the posts/pages are expired.
Thank you!
@ilker
Could you clarify where you added that line, I’m having the same problem and don’t want to wait for the update… Thanks!
The edited line is line 53 in file lib/metabox.php
I hope this helps
i had to patch lib/metabox.php to get it working (wp 3.2.1)
53c53
add_action ('admin_print_scripts', 'esape_add_datepicker_css'); --- add_action ('admin_print_styles', 'esape_add_datepicker_css');~
without this patch the proper css-file doesn’t load within the admin-pages.
Thanks for this ilker.
I shall include this in the next update
Hi there! Is it not possible to remove the expiration date from the field totally so that I could re-use that post again for something else?
For example, something that is posted and I’ve put an expiration date of a week from now on it. That date passes and it’s converted to a draft. I realize that I can change the expiration date to a new one – but what if I no longer want an expiration date on it at all? I can’t seem to delete it. Possible? Thanks so much! :)
Hello Kathy. That’s a great idea, we will implement that in the next release for you.
Oh, that’d be awesome. I’ll keep a look out for it! :) – Kathy
Hi there – the core functionility works great -however i cannot see a way to page forward to choose another month- how can a user select an expiry date from a future month (not just the current month )
Hello, some older browser don’t show the arrows, but if you hover top left or right corner in the date picker, the arrows will appear.
Hope this helps.
Hi James,
I’m sure why, but since upgrading to WP 3.2.1 I can no longer input anything into the Post Expiry Date box. I’ve tried your plugin on a few different WP installations and it seems to be the same on all. Are you aware of this issue?
Otherwise it is a fantastically simple and effective plugin.
Regards,
Christian
Hi Christian
This has been fixed with the latest release, please upgrade and it should work for you.