WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 10 months ago

#23421 assigned enhancement

Add sortable to taxonomy column

Reported by: tifosi Owned by: swissspidy
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Following on from the #21240 ticket which introduced the show_admin_column functionality one limitation is the 'as easy' way to make that column sortable.

It's possible to do it through the 'manage_edit-{$post_type}_sortable_columns' filter but the column_key is different for 3.5+. A standardisation as for adding the column may be advantageous: a register_taxonomy argument and / or new filter.

argument: show_column_sortable, boolean default false, requires show_admin_column to be set and true.

In the same way that the get_columns function uses the new "manage_taxonomies_for_{$post_type}_columns", filter to add a taxonomy column there could be a "manage_taxonomies_for_{$post_type}_sortable_columns" filter in the get_sortable_columns function of the post-list class:

i.e.

function get_sortable_columns() {
	$default = array(
		'title'    => 'title',
		'parent'   => 'parent',
		'comments' => 'comment_count',
		'date'     => array( 'date', true )
	);

	return apply_filters( "manage_taxonomies_for_{$post_type}_sortable_columns", $default );
}

The developer could then set the filter as normal

add_filter( "manage_taxonomies_for_{$post_type}_columns", 'add_sortable_column' );

function add_sortable_column ( $columns ) {
	$columns[ taxonomy-tax_name ] = 'Taxonomy Label';
	return $columns;
}

Attachments (1)

23421.diff (4.8 KB) - added by jtsternberg 4 years ago.
Allow sortable columns via the show_column_sortable taxonomy argument.

Download all attachments as: .zip

Change History (15)

#1 @SergeyBiryukov
5 years ago

  • Description modified (diff)
  • Type changed from feature request to enhancement

#2 @SergeyBiryukov
5 years ago

  • Summary changed from Follow on from #21240. Add sortable to taxonomy column to Add sortable to taxonomy column

#3 @tifosi
5 years ago

Of course above

add_filter( "manage_taxonomies_for_{$post_type}_columns", 'add_sortable_column' );

should be new filter

add_filter( "manage_taxonomies_for_{$post_type}_sortable_columns", 'add_sortable_column' );

cut n paste error.

#4 follow-up: @wonderboymusic
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.0

I actually assumed this was already there - making this work with SQL and a filter sucks (I have written some nasty SQL in my own projects). I will investigate this in 4.0, seems like it might be easy now.

#5 in reply to: ↑ 4 @jtsternberg
4 years ago

Replying to wonderboymusic:

I actually assumed this was already there - making this work with SQL and a filter sucks (I have written some nasty SQL in my own projects). I will investigate this in 4.0, seems like it might be easy now.

http://scribu.net/wordpress/sortable-taxonomy-columns.html
http://wordpress.stackexchange.com/questions/109955/custom-table-column-sortable-by-taxonomy-query
I can take a stab at this if you'd like.

#6 @wonderboymusic
4 years ago

Bring it.

@jtsternberg
4 years ago

Allow sortable columns via the show_column_sortable taxonomy argument.

#7 @jtsternberg
4 years ago

  • Keywords has-patch added; needs-patch removed

23421.diff Uses SQL and a filter, so not sure it's the best way to handle it in the long-run, but I think this is a decent place to start. I set the default for categories/tags to be true for sortable, but I'm not sure that's what we want.

#8 @jtsternberg
4 years ago

  • Keywords dev-feedback 2nd-opinion added

This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.


3 years ago

#10 @helen
3 years ago

  • Keywords 2nd-opinion removed
  • Milestone changed from 4.0 to Future Release

Bit late for this for 4.0.

#11 @johnbillion
3 years ago

  • Owner set to johnbillion
  • Status changed from new to accepted

FWIW I use the same code from Scribu in a library which we use on many of our client sites. I'll get this into 4.1.

#12 @wonderboymusic
2 years ago

  • Keywords dev-feedback removed

@johnbillion: bump

#13 @tifosi
11 months ago

@johnbillion Bump

One thing to note is that scribu's sql - which has become the defacto standard when googling for this - does a join on the terms table. The resultant output thereby strips all post records where the term is null. This may or may not be the required result.

Still, would like this to make it into 4.8 as an additional arg in 'register_taxonomy'

show_admin_sortable

Also a useful partner argument:

show_admin_filter

To enable a drilldown select to show in the options above the table. Both together would make an excellent triumvirate for taxonomy functionality.

Thanks

#14 @swissspidy
10 months ago

  • Owner changed from johnbillion to swissspidy
  • Status changed from accepted to assigned

I'll try to wrap my head around this to come up with a refreshed patch.

Note: See TracTickets for help on using tickets.