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:
https://scribu.net/wordpress/custom-sortable-columns.html
https://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!
- The topic ‘Creating Sortable Columns’ is closed to new replies.