apply_filters( "manage_{$this->screen->id}_sortable_columns", array $sortable_columns )

Filters the list table sortable columns for a specific screen.


Description Description

The dynamic portion of the hook name, $this->screen->id, refers to the ID of the current screen, usually a string.


Top ↑

Parameters Parameters

$sortable_columns

(array) An array of sortable columns.



Top ↑

Source Source

File: wp-admin/includes/class-wp-list-table.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
3.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by websupporter

    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”.

    add_filter( 'manage_edit-post_sortable_columns', 'slug_title_not_sortable' );
    function slug_title_not_sortable( $cols ) {
    	unset( $cols['title'] );
    	return $cols;
    }
    
  2. Skip to note 3 content
    Contributed by jave.web

    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:

    $my_post_type = 'flowers';
    
    // actually a screen name of the LIST page of posts
    $menu_order_sortable_on_screen = 'edit-' . $my_post_type;
    
    add_filter(
       'manage_' . $menu_order_sortable_on_screen . '_sortable_columns', 
       function( $columns ) { 
          $columns['menu_order'] = 'menu_order';
          return $columns;
       }
    );
    

    If you are interested how would you add the menu_order support to a post type in the first place:

    // the basic support
    add_post_type_support( $my_post_type, 'page-attributes' );
    
    // add a column to the post type's admin
    add_filter( 'manage_' . $my_post_type . '_posts_columns', function( $columns ) {
      $columns['menu_order'] = __( 'Order', 'textdomain' ); 
      return $columns;
    } );
    
    // display the column value
    add_action( 'manage_' . $my_post_type . '_posts_custom_column', function( $column_name, $post_id ) {
      if ( 'menu_order' === $column_name ) {
        echo __( get_post( $post_id )->menu_order, 'textdomain' );
      }
    }, 10, 2 ); // priority, number of args - MANDATORY HERE! 
    
    // ... and make it sortable with the code from the start
    

You must log in before being able to contribute a note or feedback.