Ah, one of those late-night posts. It’s gotta be good and techy.

I needed to sort by a custom field for a category. Well, let me back up. We had a calendar which had dates of the events but then also dates that the posts were actually published. Dates of the events might be in the future. We didn’t want to have to fiddle with rearranging post dates manually so the event dates were in order. Whew. Ready?

I tried my old pal Event Calendar 3. It could give me a sorted list, but I couldn’t use the thumbnails, the layout of the theme the way I wanted to. Google got me to posts with long blocks of code that I didn’t exactly know what to do with. But of course I cut and pasted and tried them anyway. It’s late, I was probably doing something wrong, but I couldn’t figure it out. Finally I read into the comments at kovshenin.com and found chasm who said to use this code: [code]query_posts(‘meta_key=position&meta_compare=>=&meta_value=1&orderby=meta_value&order=ASC’);[/code] where “position” is the custom field we’re going to sort with.

I created the custom field and then gave it the value of the date that could be easily sorted. E.g. 20101225 is Dec. 25, 2010. It worked. Gotta love the WordPress love.