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_columns
array- 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
flowers
and you want to add sorting by e.g.menu_order
you’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_order
support to a post type in the first place:Looking to sort the columns for the “sites” page in a multisite network? The following does not work as expected:
Instead, try:
As of WordPress version 6.3.0, the
$sortable_columns
parameter 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-post
screen:Ignoring the
parent
column, bothtitle
andcomments
demonstrate what a standard sortable column looks like. Thedate
column 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: