Title: Sort by a &#8220;date&#8221;
Last modified: August 19, 2016

---

# Sort by a “date”

 *  [ozpoker](https://wordpress.org/support/users/ozpoker/)
 * (@ozpoker)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/)
 * 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)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554670)
 * 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](https://wordpress.org/support/users/ozpoker/)
 * (@ozpoker)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554751)
 * Thank you
 * That sounds right – how do I change 1996-December-9 to yyyy-mm-dd in php?
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554754)
 * Give this a try:
 * `$date_for_sort = date(date_create_from_format('Y-F-d',$racedate),'Y-m-d');`
 *  Thread Starter [ozpoker](https://wordpress.org/support/users/ozpoker/)
 * (@ozpoker)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554790)
 * Thanks that set me on the right track – cheers
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554791)
 * 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.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/sort-by-a-date/#post-1554791)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
