Title: Admin list custom column sorting
Last modified: August 19, 2016

---

# Admin list custom column sorting

 *  [gbuckingham89](https://wordpress.org/support/users/gbuckingham89/)
 * (@gbuckingham89)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/)
 * Hey,
 * I’m using custom post types to store event details, including the date. The date
   is stored in the custom post type meta as a timestamp. I’ve managed to add a 
   column to the admin list that displays the timestamp. I’ve also managed to make
   the column sortable, however it seems to be sorting them in an odd order. I guessing
   that’s because the timestamp is being stored as text rather than an integer.
 * For example when sorting in descending order, the 1st February 2011 is appearing
   above 10th February 2011.
 * Any ideas on how `I can get this to sort properly? Thanks in advance.
 * Below is my code….
 *     ```
       add_filter('manage_edit-eventdate_columns', 'mv_eventdate_cols');
       add_action('manage_posts_custom_column',  'mv_eventdate_showcols');
       add_filter("manage_edit-eventdate_sortable_columns", 'mv_eventdate_sort');
   
       // Sort admin cols
       function mv_eventdate_sort($columns) {
       	$custom = array(
       		'eventdate'    => 'eventdate_start',
       		'event'    => 'eventdate_event'
       		);
       	return wp_parse_args($custom, $columns);
       }
   
       // Add remove admin columns
       function mv_eventdate_cols($columns) {
       	$columns['eventdate'] = 'Event date & time';
           $columns['event'] = 'Event name';
           unset($columns['date']);
           unset($columns['title']);
           return $columns;
       }
   
       // Show column content
       function mv_eventdate_showcols($name) {
       	global $post;
           switch ($name) {
               case 'event':
               	$eventid = get_post_meta($post->ID, 'eventdate_event', true);
               	$theevent = get_post($eventid);
                   echo '<strong><a href="/wp-admin/post.php?post='.$post->ID.'&action=edit" title="Edit this event date">';
                   echo $theevent->post_title;
                   echo '</a>';
                   echo ' - </strong>';
                   echo '<a href="/wp-admin/post.php?post='.$theevent->ID.'&action=edit" title="Edit this event">';
                   echo '(edit this event)';
                   echo '</a>';
                   break;
              	case 'eventdate' :
              		$stamp1 = get_post_meta($post->ID, 'eventdate_start', true);
              		$stamp2 = get_post_meta($post->ID, 'eventdate_end', true);
              		$allday = get_post_meta($post->ID, 'eventdate_all_day', true);
                   echo '<span style="display:none;">'.$stamp1.'</span><strong><a href="/wp-admin/post.php?post='.$post->ID.'&action=edit" title="Edit this event date">';
       			echo date('jS F Y', $stamp1);
       			echo ' - ';
       			if($allday=="yes") { echo 'All Day'; }
       			else { echo date('H:i', $stamp1)." to ".date('H:i', $stamp2); }
                   echo '</a></strong>';
                   break;
           }
       }
       ```
   

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

 *  [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1993903)
 * If the date stamp is stored as text, try strtotime function to first convert 
   it to a true time stamp, then sort….I had a similar problem and that function
   go it to work properly….beware, I did not find that strtodate was a recognized
   function, at least not in my version of WP
 *  Thread Starter [gbuckingham89](https://wordpress.org/support/users/gbuckingham89/)
 * (@gbuckingham89)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1993911)
 * Thanks, it might be silly question, but where would I need to use the strtotime
   to function?
 * Is the column being sorted by the value in the database, or the content of the
   HTML column?
 *  [salesbcocom](https://wordpress.org/support/users/sales4bcocom/)
 * (@sales4bcocom)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1993915)
 * Before you pass it to your sort function
 *  Thread Starter [gbuckingham89](https://wordpress.org/support/users/gbuckingham89/)
 * (@gbuckingham89)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1994085)
 * Still had no luck with this. If anyone else has a suggestion I would be grateful.
 *  [htz77](https://wordpress.org/support/users/tzeldin88/)
 * (@tzeldin88)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1994193)
 * I finally got the values in a custom admin column sorted correctly. See my post
   here
    [http://wordpress.org/support/topic/admin-column-sorting/](http://wordpress.org/support/topic/admin-column-sorting/)

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

The topic ‘Admin list custom column sorting’ is closed to new replies.

## Tags

 * [admin](https://wordpress.org/support/topic-tag/admin/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [htz77](https://wordpress.org/support/users/tzeldin88/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/admin-list-numerical-sorting/#post-1994193)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
