Opened 12 years ago
Last modified 3 years ago
#23421 assigned enhancement
Add sortable to taxonomy column
Reported by: | tifosi | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch dev-feedback 2nd-opinion |
Focuses: | Cc: |
Description (last modified by )
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 (4)
Change History (22)
#2
@
12 years ago
- Summary changed from Follow on from #21240. Add sortable to taxonomy column to Add sortable to taxonomy column
#4
follow-up:
↓ 5
@
11 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
@
11 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.
#7
@
11 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.
This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.
10 years ago
#10
@
10 years ago
- Keywords 2nd-opinion removed
- Milestone changed from 4.0 to Future Release
Bit late for this for 4.0.
#11
@
10 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.
#13
@
8 years 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
@
8 years 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.
#15
@
5 years ago
- Keywords dev-feedback 2nd-opinion added
I took a crack at this in 23421.3.diff—it's a more complicated feature than it seems on the face of it. Most notably, ordering by a taxonomy column, where multiple terms may be present on a single post, actually means ordering by the plain-text list of terms concatenated. So any posts with just "Term A" applied will be grouped, and then a post with "Term A, Term B" will come after.
The biggest change to the SQL was to put the taxonomy table joins into a subselect so that we don't drop posts without any terms.
After all this effort, I wonder if orderby on a taxonomy column even makes sense. It seems as though a more generic taxonomy filter (as suggested by @tifosi as a show_admin_filter option) would provide more predictable or expected results.
I used most of what @jtsternberg had, though I moved most of the functionality into the WP_Posts_List_Table since that seemed to be the precedence set by the code for show_admin_column
. I also added the setting to the WP_Taxonomy
class, and the posts_clauses
filter is applied in admin-filters.php
.
NOTE: I accidentally included another commit, I'm attempting to clean it up now...
EDIT: Fixed patch file 23421.3.diff uploaded. Sorry about that.
#16
follow-up:
↓ 17
@
5 years ago
Of note, you're new patch contains the same typo as in my patch ha ha, peform
vs perform
.
#17
in reply to:
↑ 16
@
5 years ago
Replying to jtsternberg:
Of note, you're new patch contains the same typo as in my patch ha ha,
peform
vsperform
.
Ahahaha, how did I not catch that? Oh well, this gave me an opportunity to remove an errant comment.
Of course above
should be new filter
cut n paste error.