Wordpress Events List Date Problem

Posted by Roger on Stack Overflow See other posts from Stack Overflow or by Roger
Published on 2011-01-17T21:51:37Z Indexed on 2011/01/17 21:53 UTC
Read the original article Hit count: 208

Filed under:
|
|
|

Hi,

I'm having a problem displaying events in the correct order in wordpress. I think the problem is because wordpress is treating the date as a string and ordering it by the day because it's in british date format.

The goal is to display a list of future events with the most current event at the top of the list. But I must use the british date format of dd/mm/yyyy.

Do I need to go back to the drawing board or is there a way of converting the date to achieve the result I need?

Thanks in advance :)

<ul>
<?php // Get today's date in the right format
$todaysDate = date('d/m/Y');?>

<?php  query_posts('showposts=50&category_name=Training&meta_key=date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <li>
      <h3><a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></h3>
        <?php $getDate = get_post_meta($post->ID, 'date', TRUE);
        $dateArray = explode('/', $getDate); ?>
        <?php if($getDate != '') { ?>
            <div class="coursedate rounded"><?php echo date('d F Y', mktime(0, 0, 0, $dateArray[1], $dateArray[0], $dateArray[2])); ?></div>
        <?php } ?>
        <p><?php get_clean_excerpt(140, get_the_content()); ?>...</p>
        <p><strong><a class="link" href="<?php the_permalink(); ?>">For further details and booking click here</a></strong></p>
    </li>
    <?php endwhile; ?>
    <?php else : ?>
        <li>Sorry, no upcoming events!</li>
<?php endif; ?>

© Stack Overflow or respective owner

Related posts about php

Related posts about string