Wordpress - Sorting posts by expiry date

Wordpress - Sorting posts by expiry date

I'm trying to show expired posts AFTER non-expired posts. How can I do this?

I've added a custom field "Expiration Date", in which I store the expiration dates in yyyy/mm/dd format. Problem is, if I order my results by this field, future expiry dates come first.

So I created a repeating cron-job which compares the dates and creates a secondary custom field "Expiration Date Passed" for posts whose dates have passed. I tried ordering by this field, but WP only shows posts with a value for this field - IE posts with no expiry date, or expiry dates in the future, don't show. So I tried auto-adding values '99999999' for any post which haven't expired yet. Problem is, WP can't order by custom field values THEN date- IE the first posts with value '99999999' are in a random order.

I also tried doing two queries for posts, one without expired posts, one with, then merging these two arrays. So the data is in the right order - but it screwed up WP's pagination.

Help, I'm running out of ideas!

Wordpress permalinks broken


What is the best hosting solution for a classified site using Wordpress [closed]
Since you have an "Expiration Date Passed" custom field , you could first create two sets of Posts using this custom field in your receive _posts arguments to differentiate between current & expired Posts. Wordpress - base theme [closed] $meta_key and $meta_value (string) (optional) Only show posts this contain a meta (custom) field with this key and value. wp-admin redirects to home page in my wordpress blogBoth parameters need be defined, or neither will work. WordPress custom post type Single.php?Default: None. Wordpress-like configuration for TinyMCE in Drupal extract from: http://codex.wordpress.org/Function_Reference/wp_receive _recent_posts. Wordpress: category page not for post's then you'll be able to sort each set the way you want. How to get wordpress plugin “Twitter hash” to show on page


That might work, although I am endeavor to sort the posts on my category pages. Wp_receive _recent_posts function is usually used for creating custom loops, not modifying 'the loop' in category (archive template) pages.. In the end I sorted it with this. I added this code to the top of my archive template:.
global $query_string; query_posts($query_string . "&orderby=meta_value&meta_key=Expiration Date Passed&order=DESC");   
I created a "sort" custom field called "Expiration Date Passed". A cron job then looks to see whether the post has an expiration date. If it doesn't, or if the date is in the future, it puts the post's publish date + 20 years in the sort column. If the post's expiration has passed, it puts the post's publish date in the sort column. Thus it results in the rule I was after:. 1) Posts which haven't expired, in date rule 2) Posts which have expired, in date order. Thought I would post this quick fix in case anyone else wanted to know..

95 out of 100 based on 50 user ratings 205 reviews