• Hi guys

    I wonder if someone could help me with how to do this.

    I have three custom meta fields of a custom post type that are :
    $group_race_day
    $group_race_month
    $group_race_year

    essentially allowing the user to select a date from 3 dropdown menus. eg. 2 February 2010 ($group_race_day | $group_race_month | $group_race_year)

    How can I use these three fields to allow these post to be sorted by the inputted date from a selected custom taxonomy?

    I have created a new “summed” custom field from

    $_POST[“group_race_year”].’-‘.$_POST[“group_race_month”].’-‘.$_POST[“group_race_day”]

    that returns

    1996-December-19

    Is this sortable using PHP or SQL?

    PHP is not really my thing?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you are saving the ‘summed’ date as a custom field named ‘group_race_date’, change the format to yyyy-mm-dd. Then you can sort by using:

    $args = array(
       'meta_key' => 'group_race_date',
       'orderby' => 'meta_value',
    );
    query_posts($args);

    Add any other parameters to $args that you need for the query.

    Thread Starter ozpoker

    (@ozpoker)

    Thank you

    That sounds right – how do I change 1996-December-9 to yyyy-mm-dd in php?

    Give this a try:

    $date_for_sort = date(date_create_from_format('Y-F-d',$racedate),'Y-m-d');

    Thread Starter ozpoker

    (@ozpoker)

    Thanks that set me on the right track – cheers

    You are welcome! Now, please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Sort by a “date”’ is closed to new replies.