Filters the list table sortable columns for a specific screen.
Description
The dynamic portion of the hook name, $this->screen->id, refers to the ID of the current screen.
Parameters
$sortable_columnsarray- An array of sortable columns.
Source
$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
As an example. When you see the table with the posts in the admin screen, you can sort the posts by title. If you wanted to remove the ability to sort by the title you could do the following:
The screen ID for the posts overview page in the admin is
edit-post, so the filter would be “manage_edit-post_sortable_columns”.For the list of custom type, the hook name is a COMBINATION of edit and the custom post type, so let’s say you have custom post type
flowersand you want to add sorting by e.g.menu_orderyou’ve added before, the hook would be called “manage_edit-flowers_sortable_columns’ – the hook code could look something like:If you are interested how would you add the
menu_ordersupport to a post type in the first place:As of WordPress version 6.3.0, the
$sortable_columnsparameter is now a multidimensional array where you can also now specify abbreviations, orderby text, and the initial sorting order. For example, this is what is dumped for theedit-postscreen:Ignoring the
parentcolumn, bothtitleandcommentsdemonstrate what a standard sortable column looks like. Thedatecolumn is initialised to display the posts in descending order.Using jave.web’s example from 4 years ago, the code could now look like this:
Looking to sort the columns for the “sites” page in a multisite network? The following does not work as expected:
Instead, try: