By default the title column on a post/page/custom post type page in WordPress admin area is sortable.

How can I disable the sorting option?

enter image description here

I think the question is clear but just to extend it a little bit.

I am customizing the custom post types page in the admin area.

My code:

add_filter( 'manage_sponsor_posts_columns', 'kiran_set_columns' );

function kiran_set_columns( $columns ) {
    $newColumns = array();
    $newColumns['title'] = 'Sponsor';
    return $newColumns;
}

I do not want the title column to provide the sorting feature.

1 Answer
1

The filter hook manage_edit-post_sortable_columns contains all the columns, which are sortable. So you could hook into this filter and unset the title:

<?php

add_filter( 'manage_edit-post_sortable_columns', 'wse_240787' );
function wse_240787( $col ) {
    unset( $col['title'] );
    return $col;
}

This filter is documented in wp-admin/includes/class-wp-list-table.php:

  /**
     * Filters the list table sortable columns for a specific screen.
     *
     * The dynamic portion of the hook name, `$this->screen->id`, refers
     * to the ID of the current screen, usually a string.
     *
     * @since 3.5.0
     *
     * @param array $sortable_columns An array of sortable columns.
     */
$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );

Since our current screen Id is edit-post the filter is manage_edit-post_sortable_columns.

If you are using a custom post type, the screen ID would change to edit-{$cpt_slug}. For example for pages it would be edit-page. If your CPT is sponsor, it would be edit-sponsor. (Thanks @bravokeyl for pointing to this).

Leave a Reply

Your email address will not be published. Required fields are marked *