DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Change Sortable Columns In WordPress

Change Sortable Columns In WordPress

Paul Underwood user avatar by
Paul Underwood
·
Feb. 06, 15 · Interview
Like (0)
Save
Tweet
Share
7.69K Views

Join the DZone community and get the full member experience.

Join For Free

In a previous tutorial we saw how you can recreate the All Posts table in the WordPress admin area by using the WP_List class in WordPress.

It talks about creating your own table and populating it with any data that you need. It talks about how you can customise the table to behaviour in anyway that is needed by adding different columns to the table, assigning sortable columns to the table, pagination and searching the data, just like you can in the All posts table.

But in this previous tutorial only explains how to create sortable columns on a new table, in this tutorial we are going to look at changing an existing table to apply new sortable columns.

To edit the columns and change them to be sortable we need to use a filter and return is a set of column IDs of what columns we want to be sortable. The filter we need to use is manage_edit-{$this->screen->id}_sortable_columns.

add_filter( 'manage_edit-{$this->screen->id}_sortable_columns', 'manage_sortable_columns');

The below code snippet will change the author column on the posts screen to be sortable.

class Pu_Manage_Sortable_Columns
{
    public function __construct()
    {
        add_filter( 'manage_edit-post_sortable_columns', array($this, 'manage_sortable_columns'));
    }

    public function manage_sortable_columns( $columns )
    {
        $columns['author'] = 'Author';

        return $columns;
    }
}

Now you will see that the author column is sortable which is noticeable by the sort arrow appearing next to the Author title on the hover event. Clicking on the author title will now sort the table data by the Author name.

Database WordPress

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The Power of Docker Images: A Comprehensive Guide to Building From Scratch
  • Introduction to Container Orchestration
  • Stop Using Spring Profiles Per Environment
  • What Are the Benefits of Java Module With Example

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: