In the past, we have shared how to expire posts in WordPress using the Post Expirator Plugin. Well, when creating an event listing site, we found this plugin to be super helpful. We can easily delete the event listings that are expired. Secondly, thanks to this plugin, it is really easy to sort posts by post expiration date as well. In this article, we will show you how to sort posts by post expiration date in WordPress.
Code Updated to reflect the changes in the plugin where they changed the name of the custom field. Thanks Tajim for letting us know in the comments.
In our particular project, we had Events as a Custom Post Type. Now this is for a non-profit that holds like one event per month, so we simply created a loop to put in their events page. You can use the code in your sidebar, or anywhere else you want.
Tables can't be imported directly. Please insert an image of your table which can be found here.
1 2 3 4 5 6 7 8 9 10
The trick is to utilize the meta_key and then user oderby meta_value. Putting it in Ascending Order shows the event that is coming soon (expiring soonest). Example of our events listing:
Note in order for this to work, you MUST use the Post Expirator Plugin.