[wp-hackers] WP_List_Table class & sortable columns

24/7 24-7 at gmx.net
Wed Nov 16 22:43:13 UTC 2011


During developing a plugin, I added a table (extension for the 
WP_List_Table class [1]) to a meta box on post/page/CPT screens. Everything 
worked fine: I got around pagination and several other stuff, but got stuck 
with ordering the columns. The link broke on the "orderby" argument and 
only returned the very first character "p" instead the whole string 
"post_date".

That didn't work (the docBlock of the WP_List_Table class says it works):
public function get_sortable_columns() 
{
return array(
 'ID' => 'ID'
,'post_title' => 'post_title'
,'post_date' => 'post_date'
);
}

Here's what worked:
public function get_sortable_columns() 
{
return array(
 'ID' => array( 'ID', true )
,'post_title' => array( 'post_title', true )
,'post_date' => array( 'post_date', true )
);
}

When I look at get_column_info() in WP_List_Table then I simply don't get 
around the "why the heck does this happen"? I already checked if there are 
filters present on 
$GLOBALS['wp_filter']["manage_{$screen->id}_sortable_columns"]; but it's 
empty.

Can someone be so kind and explains this to me? Thanks!

Best wishes,
Kaiser.

[1] /core_root/wp-admin/includes/class-wp-list-table.php


More information about the wp-hackers mailing list