• I have a widget that is working but it orders results by the end date and not the start date. I use custome variables to set the start date (startDate) and end date (endDate) when creating a post. the site is http://pleinairbc.com

    The original code was:
    query_posts('showposts=20&category__and(events_paid,events_free)&meta_key=endDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_key&order=ASC');

    which you can see will order by the end date

    I changed it to..
    query_posts('showposts=20&category__and(events_paid,events_free)&meta_key=endDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=startDate&order=ASC');

    thinking it would order by start date (startDate) but it still orders by end date.

    Any ideas how I would get it to sort via the start date even though I compare with the end date?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Have you tried order=DESC?

    Thread Starter mrkingid

    (@mrkingid)

    Just did. It sorts via the endDate in decending order. Not really what I am looking for. But thanks.

    Thread Starter mrkingid

    (@mrkingid)

    Hmmmm,

    I have even tried this with no luck.

    $meta_key2 = 'startDate';
    
    query_posts('showposts=20&category__and(events_paid,events_free)&meta_key=endDate&meta_compare=>=&meta_value='.$todaysDate. '&orderby=key2.meta_value&order=ASC' );

    and this

    $meta_key2 = 'startDate';
    
    query_posts('showposts=20&category__and(events_paid,events_free)&meta_key=endDate&meta_compare=>=&meta_value='.$todaysDate. '&orderby=meta_key2&order=ASC' );

    What happens if you change the meta_key to startDate?
    query_posts('showposts=20&category__and(events_paid,events_free)&meta_key=startDate&meta_compare=>=&meta_value='.$todaysDate.'&orderby=meta_key&order=ASC');

    Thread Starter mrkingid

    (@mrkingid)

    It sorts the list correctly, however the events that have a range where the start day falls before the todaysDate do not show up, thus the need to sort via the endDate.

    If I knew how to code options into widgets I could try to separate the two different types of data – upcoming and current.

    hmmmmmmmmmmmmmmmmmmm

    In a site I did, I used the following code (without a widget) to list upcoming events and placed it before the loop:

    <?php // Get today's date in the right format
    $todaysDate = date('Y/m/d');
    ?>
    
    <?php query_posts('showposts=3&category_name=events&meta_key=Date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>

    The ‘Date’ custom field was in this format: 2010/05/10 00:00:00 and it worked out fine.

    Sorry I can’t be of more help.
    Good luck.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘widget coding :: orderby not working’ is closed to new replies.