Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#24313 closed feature request (wontfix)

Filter Columns by View

Reported by: chriscct7's profile chriscct7 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

After searching extensively for a way to do this, and discussing this with fellow WordPress developers, I believe I have found a feature that should be added to WordPress.

When you make a new custom post type, if you have WordPress register a UI for it, it outputs a screen named "All XXXX's". Within these, WordPress automatically adds filters. So let's say I've registered a CPT called Downloads.

So I can now use the built in UI for Downloads and filter the page to show just pending downloads, or just published downloads, for instance.

However, the issue becomes what if you want to display a column for some views, but not others. For instance, if Downloads has a column called "Sales" where the number of sales of that particular download is stored, it makes no sense to show that column on Pending Downloads (since they can't have sales before being published).

Currently, at least after days of trying to find a way of doing this, there is no way to do this for the tables registered by WordPress. If I make my own List_Table, then I can do this.

However, there should be a way of adding columns based on filter, so that a developer who adds a column programmatically can go:

if($view != pending){
// register sales column

Feel free to correct me if I've overlooked a method of doing this.


Change History (8)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Appearance to Administration
  • Description modified (diff)

#2 @mordauk
11 years ago

  • Cc pippin@… added

#3 @sunnyratilal
11 years ago

  • Cc sunnyratilal5@… added

#4 @johnbillion
11 years ago

  • Cc johnbillion added

#5 @chriscct7
11 years ago

I think if someone from the core team took a look at this, this could very easily be solved for 3.6 by simply either passing the current view into the manage_edit-$cptname_columns or making a function you can call to get the current screen view.

#6 @chriscct7
11 years ago

Found a way around this. Will post in a sec.

#7 @chriscct7
11 years ago

This is what you can use. I'm using it to remove columns, but you could use it to add new ones conditionally as well.

function column_headers( $defaults ) {
    // Check that this is not all view, else it throws an error
    if ( isset( $_REQUEST[ 'post_status' ] ) ) {
        // Remove the sales from pending and draft products
        if ( $_REQUEST[ 'post_status' ] == 'pending' || $_REQUEST[ 'post_status' ] == 'draft' ) {
            unset( $defaults[ 'sales' ] );
add_filter( 'manage_edit-download_columns', array( $this, 'column_headers' ) );
Last edited 9 years ago by chriscct7 (previous) (diff)

#8 @chriscct7
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This is probably best handled the way I demonstrated 2 years ago. Closing as wontfix.

Note: See TracTickets for help on using tickets.