WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 14 months ago

#23421 accepted enhancement

Add sortable to taxonomy column

Reported by: tifosi Owned by: johnbillion
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch dev-feedback
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 16 months ago.
Allow sortable columns via the show_column_sortable taxonomy argument.

Download all attachments as: .zip

Change History (12)

comment:1 @SergeyBiryukov3 years ago

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

comment:2 @SergeyBiryukov3 years ago

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

comment:3 @tifosi3 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.

comment:4 follow-up: @wonderboymusic16 months 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.

comment:5 in reply to: ↑ 4 @jtsternberg16 months 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.

@jtsternberg16 months ago

Allow sortable columns via the show_column_sortable taxonomy argument.

comment:7 @jtsternberg16 months 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.

comment:8 @jtsternberg16 months ago

  • Keywords dev-feedback 2nd-opinion added

comment:9 @ircbot14 months ago

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

comment:10 @helen14 months ago

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

Bit late for this for 4.0.

comment:11 @johnbillion14 months 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.

Note: See TracTickets for help on using tickets.