Using List Table Filters for ALL Custom Post Types

Is there a way to create sortable columns for admin tables across ALL post types?

I am working on a project with 7 Custom Post Types, and wondering if there is a better approach than using multiple manage_edit-{Post-Type-Here}_sortable_columns filters for each post type.

1 Answer
1

You’re going to have to use the filters for each post type anyway. If you plan to leverage a bunch of dynamic filters that all call for all 7 post type slugs you could stick them in an array and loop through the filters with a foreach. Saves a little bit of code at least.

$post_types = array(
    'ptype_one', 'ptype_two', 'ptype_three', 'ptype_four',
    'ptype_five', 'ptype_six', 'ptype_seven'
);

foreach ( $post_types as $type ) {
    add_filter( "manage_edit-{$type}_sortable_columns", "your_callback" );
}

Leave a Comment