Using WordPress ‘manage_{$this->screen->id}_sortable_columns’ PHP filter

The manage_{$this->screen->id}_sortable_columns WordPress PHP filter allows you to modify the sortable columns for a specific admin screen.

Usage

add_filter('manage_{$this->screen->id}_sortable_columns', 'my_custom_sortable_columns');

function my_custom_sortable_columns($sortable_columns) {
    // your custom code here
    return $sortable_columns;
}

Parameters

  • $sortable_columns (array) – An array of sortable columns.

More information

See WordPress Developer Resources: manage_{$this->screen->id}_sortable_columns

Examples

Make a custom column sortable

Make a custom ‘Price’ column sortable in the ‘Products’ admin screen.

add_filter('manage_edit-products_sortable_columns', 'make_price_column_sortable');

function make_price_column_sortable($sortable_columns) {
    $sortable_columns['price'] = 'price';
    return $sortable_columns;
}

Remove a sortable column

Remove the ‘Author’ column from the sortable columns in the ‘Posts’ admin screen.

add_filter('manage_edit-post_sortable_columns', 'remove_author_sortable_column');

function remove_author_sortable_column($sortable_columns) {
    unset($sortable_columns['author']);
    return $sortable_columns;
}

Change the default sort order

Change the default sort order of a custom ‘Priority’ column to descending in the ‘Tasks’ admin screen.

add_filter('manage_edit-tasks_sortable_columns', 'change_priority_column_sort_order');

function change_priority_column_sort_order($sortable_columns) {
    $sortable_columns['priority'] = array('priority', true);
    return $sortable_columns;
}

Add multiple sortable columns

Add multiple custom columns (‘Height’, ‘Width’) as sortable in the ‘Artworks’ admin screen.

add_filter('manage_edit-artworks_sortable_columns', 'add_multiple_sortable_columns');

function add_multiple_sortable_columns($sortable_columns) {
    $sortable_columns['height'] = 'height';
    $sortable_columns['width'] = 'width';
    return $sortable_columns;
}

Modify sortable columns for a custom post type

Add a custom ‘Rating’ column as sortable and remove the ‘Date’ column from the sortable columns in the ‘Reviews’ custom post type admin screen.

add_filter('manage_edit-reviews_sortable_columns', 'modify_sortable_columns_for_reviews');

function modify_sortable_columns_for_reviews($sortable_columns) {
    $sortable_columns['rating'] = 'rating';
    unset($sortable_columns['date']);
    return $sortable_columns;
}