/ Published in: PHP
Put this before the loop in archive.php to have posts in the archive for category '26' sorted by custom field 'date'. Assign sortable values like '090501' or '2009-05-01' to those fields when editing posts and your Upcoming Events will be sorted by the future date at which they will take place.
Expand |
Embed | Plain Text
<?php if (is_category('26')) { $posts = query_posts($query_string. '&orderby=meta_value&meta_key=date&order=DESC' ); } ?>
Comments
Subscribe to comments
You need to login to post a comment.

You just saved the day :) Amazing snippet.
Would this also work if I assigned a dollar value to a custom field? Say I wanted to sort the posts from highest to lowest for a site that had a site that sold screw drivers.
If I used a custom field of price and assigned a value of $7.00 , $8.00 , $10,000 , etc -- would the same principle work? Could someone assist me with that code?
You are the MAN!
Thanks everyone and sorry for replying so late, I didn't expect anyone to view this little snippet, let alone comment on it...
Hello! Is it any way to change this code so it will show the post even if date-field is empty? I would be happy if I could get them to appear last but i cant see them at all...
To get a custom sort order for the on the previous/next post links, see: http://snipplr.com/view/48060/custom-sorting-for-previousnext-post-links/