Forums

WordPress Posts As Events (1 post)

  1. Chris H
    Member
    Posted 5 months ago #

    I've been working on a method that will allow me to use WordPress as an event calendar. My method uses WordPress custom fields, and allows my clients to add events to their site via a front end, password protected form (built using Gravity Forms), but there is one part of the process that isn't as clean as I like.

    When the client adds an event, the last parameter/custom field on the form that they are required to fill in is the 'Sort Date'. This value is calculated by inserting the event date in the following format - YYYYMMDD. I then sort the posts in ascending order according to the 'Sort Date' value using this code:

    <?php if (have_posts()) : ?>
    
    <?php query_posts($query_string . '&meta_key=sortdate&orderby=meta_value&order=asc' );  ?>
    
    <?php while (have_posts()) : the_post(); ?>

    It works well, and is reasonably easy for people to understand, however I would like to eliminate the 'Sort Date' part of the process all together.

    What I'd like to know is if there is a way to sort my posts according to three separate custom fields (Year, Month and Day) combined to make one value? In other words, the required information has already been entered into the form before the client reaches the 'Sort Date' input box (in the preceding day, month and year fields). Can I combine these values into one value, and then sort my posts according to that combined value?

    Hope that all makes sense. Happy to clarify if I haven't been clear on anything. I'm also planning on writing up a full tutorial that explains the entire technique and sharing it online once I've got it working as I want it.

    Cheers,

    Chris

Reply

You must log in to post.

About this Topic