2

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

2

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" );
}
2
  • Thanks Drew, this is exactly what I am looking at now. My curiosity was piqued after discovering a Tuts+ article which describes in the "Other Usages" section that by using manage_posts_columns and manage_posts_custom_column hooks, the custom column will be shown in all manage posts screens (ie: across all custom post types). Apparently, for whatever reason, the same sort of thing does not hold true for the sortable column filters.
    – Dub Tempo
    Commented Sep 7, 2014 at 23:30
  • Yeah, good call on the double quotes. I just didn't think about it :) Commented Sep 8, 2014 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.