Title: [Plugin: Post Expirator] Loop code for sorting by expiration date?
Last modified: August 19, 2016

---

# [Plugin: Post Expirator] Loop code for sorting by expiration date?

 *  [Robin Cannon](https://wordpress.org/support/users/fogofeternity/)
 * (@fogofeternity)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/plugin-post-expirator-loop-code-for-sorting-by-expiration-date/)
 * Hey
 * Perfect plugin for what I needed.
 * I’m looking to have a template that sorts posts by expiration date, with the 
   soonest expiring post at the top of the list.
 * Any post_query terms usable with the plugin, or alternative PHP code for sorting?
 * Cheers
 * Robin
 * [http://wordpress.org/extend/plugins/post-expirator/](http://wordpress.org/extend/plugins/post-expirator/)

Viewing 1 replies (of 1 total)

 *  [adrian271](https://wordpress.org/support/users/adrian271/)
 * (@adrian271)
 * [16 years ago](https://wordpress.org/support/topic/plugin-post-expirator-loop-code-for-sorting-by-expiration-date/#post-1448029)
 * Maybe I can get you started with what I have. I only used this to sort and show
   one event but you can probably build this. I eventually want to make it so that
   when somebody clicks on an events category it specifically sorts these by expiration…
   I’ll post that later when it’s done.
 * But for now here is what is on my home.php page:
 *     ```
       <?php 	$events_query = new WP_Query('category_name=upcoming-events&showposts=1&order=ASC&meta_key=expiration-date&orderby=meta_value');
       while ($events_query->have_posts()) : $events_query->the_post(); 	?>
       <div id="events">
          <p>Come to our event:  <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </p>
       </div>
       <?php endwhile; ?>
       ```
   
 * So as you can tell this is for events and I have this only displaying one event,
   the next upcoming event.
 * Now if I could only get that data from the post expirator and use it to display
   the event date… but that’s is a different battle.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Post Expirator] Loop code for sorting by expiration date?’ is
closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [adrian271](https://wordpress.org/support/users/adrian271/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/plugin-post-expirator-loop-code-for-sorting-by-expiration-date/#post-1448029)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
