Another thought I had was to create a custom form using Gravity Forms that contained all of the fields for an event (event, location, date, ticket price) and having him create events via a front end form that then publishes a post.
My thinking behind this was that (somehow!) I could create a chronological number from the date entered (Aug 11, 2011, for example, would convert to 20110811), and then somehow sort the posts via this number. I have no idea whether this is possible, or if my thinking is totally flawed. Any advice would be very appreciated! š
OK, so this code, placed immediately before if (havePosts()) in my category template does appear to affect the sort order of the posts:
<?php query_posts($query_string . '&meta_key=sortdate&orderby=meta_value'); ?>
I’ve created a custom field called ‘sortdate’ and in here have entered a numeric representation of the event date (June 23rd, 2011 is 20110623). Only issue is that it is sorting them in the wrong direction. The closest (in date) shows are at the bottom of the page, whilst the furthest ones are displayed at the top. If I can figure out how to reverse this order, I think this will be sufficient. Any thoughts?
Cheers,
Chris
For anyone who’s interested, I solved the problem above with the following code:
<?php query_posts($query_string . '&meta_key=sortdate&orderby=meta_value&order=asc' ); ?>
By adding a custom field called sortdate to each post in the ‘Events’ category, and making the value of that field the date of the event in reverse order (YYYYMMDD), I was able to sort the posts as I required. š
@chris H Thanks so much for posting this. I used this little bit of code to organize my blog posts by event date, rather than by date posted. Really handy little trick.
Hi Chris H,
Thanks for posting this.
I’ve been having a similar problem and after playing around with some events plugins and having no luck, I decided to use your method.
Is it possible to only show posts where the date is greater than or equal to the current date?
i.e. not show posts/evnts that have already happened.
I have tried the following method but am having no joy…
<?php query_posts($query_string . ‘&meta_key=sortdate&meta_compare=>=meta_value=CURDATE()&meta_key=sortdate&orderby=meta_value&order=asc’ ); ?>
Can anybody help on this one please?