How to create an archive based on custom fields, not publish date in WordPress
We recently launched a site called theforgottenletters.org, an incredible project dedicated to translating the Holocaust-era letters of Ralph Schwab from German to English. While building the site, we needed to archive the letters based on the dates the letters were written, not when we publish them to the site.
First, I tried this tutorial: How To Make a WordPress Events List and calendar plugins, but the tutorial wasn’t comprehensive enough and the plugins were too complex to start messing with.
The solution
I found this wonderful date field plugin which lets you sort posts by the date entered in the custom fields. Here’s what I did:
1. Upload the plugin and activate it
2. Opened the lettersarchive.php page template I created and added a query. The query checks for posts in the Letters category that have a date filled in and the orders it from oldest to newest.
<?php query_posts(‘category_name=letters&meta_key=date_value&orderby=meta_value&order=DESC’); ?>
3. I replaced a typical date function within the loop <?php the_time(‘j M Y’); ?> with
<?php echo date(“l jS \of F Y”, get_post_meta($post->ID, ‘date_value’, true));?>
4. I created a new post, assigned it to the Letters category, and selected a date from the date picker box that now appears below the editing box in the post area.

I noticed that the Date Field plugin only lets you select a date up to 5 years ago so I had to hack the plugin file on line 125 to reflect selecting dates from 80 years ago.
for($currentyear = date(‘Y’) – 80; $currentyear <= date(Y) +5;$currentyear +=1)
Here’s a screenshot of the archive from The Forgotten Letters site.

Category: Code Snippets, Tips








[...] the entire solution on WPGarage. AKPC_IDS += "98,";Popularity: unranked [?] Categories: Plugins, [...]
The one problem with this method is that it needs to query all the posts in that category order to sort them correctly. This is fine if you only have a small number of letters (say less than a 100) and should work a lot of situations, but if you start to go above that you’re looking at a lot of queries which can weigh down your server. I also forget if paging worked with this method.
I had a similar issue when I was building an events post (http://wptheming.com/2010/08/how-to-make-an-events-custom-post-type/). I originally used the sort you describe, but then decided to hijack the post date instead because of the better query capabilities. Still haven’t found the perfect solution.