Title: [Plugin: Event] Adding sortable custom columns to admin screen
Last modified: August 31, 2016

---

# [Plugin: Event] Adding sortable custom columns to admin screen

 *  [phil_maly](https://wordpress.org/support/users/phil_maly/)
 * (@phil_maly)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/plugin-event-adding-sortable-custom-columns-to-admin-screen/)
 * This plugin is currently showing the custom column event_date just fine but I’d
   like to be able to sort it on the WordPress admin back-end like the other columns
   that already exist, (Title and Date).
 * This is for the custom post type event. I thought this could be handled with 
   the add_filter for manage_custom-post-type_sortable_columns function. What am
   I missing?
 *     ```
       <?php
       /**
        * Plugin Name: Event
        * Description: Event Schedule.
        * Version: latest
        * Author: Infoway
        * Author URI: http://URI_Of_The_Plugin_Author
        * License: GPL2
        */
       ?>
       <?php
       ob_start();
       global $table_prefix;
       define('EVENT_PLUGIN_PATH',  dirname(__FILE__));
       define('EVENT_PLUGIN_URL',  plugin_dir_url(__FILE__));
       define('EVENT', 'event');
       define('EVENT_CAT', 'event_cat');
       /*TBL Define*/
       define('LOCATION_TBL', $table_prefix.'location');
   
       register_activation_hook(__FILE__, 'event_actvation');
   
       add_filter('manage_'.EVENT.'_posts_columns', 'custom_column_name_func',10,2);
       add_action( 'manage_'.EVENT.'_posts_custom_column' , 'custom_column_value_func', 10, 2 );
   
       function custom_column_name_func($columns) {
           unset($columns['date']);
           $columns['event_date'] = 'Event Date';
           $columns['date'] = 'Date';
           return $columns;
       }
   
       function custom_column_value_func($columns,$post_id){
           $event_date = get_post_meta($post_id, '_ev_start_date', true);
           switch ( $columns ) {
               case 'event_date':
                   echo date('F j, Y', $event_date);
               break;
           }
       }
   
       function custom_column_sort($columns) {
       	$custom = array(
       		'Event Date' 	=> 'event_date'
       	);
       	return wp_parse_args($custom, $columns);
       }
       add_filter("manage_'.EVENT.'_sortable_columns", 'custom_column_sort');
   
       function custom_column_orderby( $vars ) {
       	if ( isset( $vars['orderby'] ) && 'event_date' == $vars['orderby'] ) {
       		$vars = array_merge( $vars, array(
       			'meta_key' => 'event_date',
       			'orderby' => 'meta_value'
       		) );
       	}
       	return $vars;
       }
       add_filter( 'request', 'custom_column_orderby' );
       ```
   

The topic ‘[Plugin: Event] Adding sortable custom columns to admin screen’ is closed
to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [phil_maly](https://wordpress.org/support/users/phil_maly/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/plugin-event-adding-sortable-custom-columns-to-admin-screen/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
