Title: Creating Sortable Columns
Last modified: August 19, 2016

---

# Creating Sortable Columns

 *  [Chee Studio](https://wordpress.org/support/users/chee-studio/)
 * (@chee-studio)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/creating-sortable-columns/)
 * Hi all,
 * I’m attempting to get a handle on the Sortable columns that come with 3.1. I 
   already know how to create custom columns (although it seems there’s a few ways
   to get custom field information into a custom column). I’ve worked with these
   two tutorials:
 * [http://scribu.net/wordpress/custom-sortable-columns.html](http://scribu.net/wordpress/custom-sortable-columns.html)
 * [http://stereointeractive.com/blog/2011/02/26/wordpress-3-1-sortable-admin-tables/](http://stereointeractive.com/blog/2011/02/26/wordpress-3-1-sortable-admin-tables/)
 * Neither of which I can to work. I am wondering if someone can walk me through
   how to create a sortable column for a custom field called “Sort.”
 * Here is what I currently have as a custom column that is pulling the Sort field,
   which I’d like to make sortable:
 * ‘add_action(“manage_posts_custom_column”, “my_testimonials_columns”);
    add_filter(“
   manage_edit-testimonial_columns”, “my_testimonial_columns”);
 * function my_testimonial_columns($columns)
    { $columns = array( “cb” => “<input
   type=\”checkbox\” />”, “title” => “Title”, “Sort” => “Sort” ); return $columns;}
 * function my_testimonials_columns($column)
    { global $post; $sort = get_post_meta(
   $post->ID, ‘Sort’); if (“ID” == $column) echo $post->ID; elseif (“Sort” == $column)
   echo $sort[0]; }’
 * I realize this is probably not the best way to create custom columns and I am
   open to streamling this code. I have no idea how to get this code to merge with
   the new _sortable_columns filter.
 * Many thanks in advance!

Viewing 1 replies (of 1 total)

 *  Thread Starter [Chee Studio](https://wordpress.org/support/users/chee-studio/)
 * (@chee-studio)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/creating-sortable-columns/#post-1983463)
 * Actually, I figured this out! I just needed to register the column as Sortable,
   since the way I configured the columns seemed to be working great.
 * So, using the above example, I added this right below the above code:
 * ‘// Register the column as sortable
    function sort_column_register_sortable( 
   $columns ) { $columns[‘Sort’] = ‘Sort’;
 *  return $columns;
    } add_filter( ‘manage_edit-testimonial_sortable_columns’, ‘
   sort_column_register_sortable’ );’
 * Working great now! Hopefully this will provide a comprehensive code snippet from
   start to finish for somebody else trying to get sortable columns going! 🙂

Viewing 1 replies (of 1 total)

The topic ‘Creating Sortable Columns’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [Chee Studio](https://wordpress.org/support/users/chee-studio/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/creating-sortable-columns/#post-1983463)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
