WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 9 months ago

#28232 new enhancement

Custom Taxonomy filter on post listing pages

Reported by: jtsternberg Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: needs-patch has-ui-feedback
Focuses: administration Cc:

Description

Currently core adds a category dropdown filter to the admin post listing pages. I propose that there ought to be a parameter passed in to register_taxonomy similar to the show_admin_column (#21240) that would enable a filter dropdown for your custom taxonomy. Maybe 'taxononomy_filter' => true. I was sure a ticket would probably exist for this feature request, but was unable to find one.

Attachments (6)

28232.diff (1.6 KB) - added by wonderboymusic 5 years ago.
28232-alternate.diff (1.3 KB) - added by husobj 4 years ago.
Wireframe1.png (623.3 KB) - added by JoshuaWold 19 months ago.
UI exploration of this ticket
extended_cpt_01.png (225.0 KB) - added by runofthemill 19 months ago.
extended_cpt_02.png (182.4 KB) - added by runofthemill 19 months ago.
extended_cpt_03.png (242.0 KB) - added by runofthemill 19 months ago.

Download all attachments as: .zip

Change History (20)

@wonderboymusic
5 years ago

#1 @wonderboymusic
5 years ago

  • Keywords has-patch needs-refresh added
  • Milestone changed from Awaiting Review to Future Release

28232.diff will get the dropdowns on the page. The query is built bizarrely, haven't figured it out yet.

#2 @SergeyBiryukov
5 years ago

__( 'View all ' ) . $other->labels->name is not localizable, see ticket:17609:3 and ticket:19099:1.

We can just use $other->labels->all_items (and also remove the "View" prefix from "View all categories"), which would be consistent with [27626].

#3 @husobj
4 years ago

Hi

I just discovered this ticket after working on a patch myself.
I will attach my patch 28232-alternate.diff for reference in case it's any use.

It's pretty similar although I have based my approach on the same way that 'show_admin_column' is implemented in terms of code structure.

I found that if I passed 'value_field' => 'slug' in wp_dropdown_categories() which was introduced in a recent-ish version of WP then the query just works as it queries the slug in the same way that the 'show_admin_column' terms links do.

#4 follow-up: @boonebgorges
4 years ago

  • Keywords needs-patch added; has-patch needs-refresh removed

This seems like a good feature to me. A few comments on [28232-alternate.diff]:

  • sprintf( __( 'Filter by %s' ), $taxonomy->labels->singular_name ) is not properly localizable, because of the way many languages will decline the taxonomy name. If we want the screen-reader-text to match that of the Category dropdown, then we'll need a new taxonomy label - something like 'filter_by_item'. @SergeyBiryukov does this seem right to you?
  • We should pass 'hide_if_empty' => true to wp_dropdown_categories() - taxonomies with no terms should not have dropdowns here.
  • Let's use booleans instead of integers when building the wp_dropdown_categories() argument array. (Never mind that the Category dropdown does it the other way.)
  • Not all taxonomies will have a non-false query_var, and I don't think we need to depend on the existence of query_var to make this feature work. I recommend doing something like this: if the taxonomy has a non-boolean query_var, use it; otherwise use sanitize_title_with_dashes( $taxonomy->name )
  • We need better escaping (esc_attr()) in the <label> element.
  • Why bother getting the 'objects' from get_object_taxonomies() and filtering down to 'name' on the next line, only to call get_taxonomy() in the foreach loop? I'd suggest removing the fourth param ('name') in wp_filter_object_list().

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

Replying to boonebgorges:

sprintf( __( 'Filter by %s' ), $taxonomy->labels->singular_name ) is not properly localizable, because of the way many languages will decline the taxonomy name. If we want the screen-reader-text to match that of the Category dropdown, then we'll need a new taxonomy label - something like 'filter_by_item'. @SergeyBiryukov does this seem right to you?

Yes, either that or a workaround like __( 'Filter by taxonomy: %s' ).

#6 @johnbillion
4 years ago

  • Focuses administration added
  • Keywords ui-feedback added
  • Version 4.0 deleted

I think this should be opt-in, either on a per-post-type or per-taxonomy basis. If a custom post type has more than about three custom taxonomies then the screen will get really cluttered.

#7 @boonebgorges
4 years ago

I think this should be opt-in

+1. I was imagining it being on a per-taxonomy basis, but I could imagine 'show_admin_filter' also accepting an array of post types.

#8 @melchoyce
2 years ago

If this is still relevant, can someone post screenshots for review?

This ticket was mentioned in Slack in #design by melchoyce. View the logs.


19 months ago

@JoshuaWold
19 months ago

UI exploration of this ticket

#10 @JoshuaWold
19 months ago

@wonderboymusic @husobj wanted to followup and see if this sketch is what you had in mind for how taxonomies would display in the post list page?

This ticket was mentioned in Slack in #design by joshuawold. View the logs.


19 months ago

#12 @runofthemill
19 months ago

Saw this on Slack and shared with @JoshuaWold https://github.com/johnbillion/extended-cpts which provides the functionality (and more) covered by this ticket. Above are a couple of quick screens of how it looks in WP Admin!

#13 @karmatosed
12 months ago

  • Keywords has-ui-feedback added; ui-feedback removed

#14 @drzraf
9 months ago

The query tweak needed is here: http://scribu.net/wordpress/sortable-taxonomy-columns.html

                $clauses['join'] .= <<<SQL
LEFT OUTER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID={$wpdb->term_relationships}.object_id
LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
LEFT OUTER JOIN {$wpdb->terms} USING (term_id)
SQL;
                $clauses['where'] .= " AND (taxonomy = 'color' OR taxonomy IS NULL)";
                $clauses['groupby'] = "object_id";
                $clauses['orderby']  = "GROUP_CONCAT({$wpdb->terms}.name ORDER BY name ASC) ";
                $clauses['orderby'] .= ( 'ASC' == strtoupper( $wp_query->get('order') ) ) ? 'ASC' : 'DESC';

What is needed is an easy and structured way to wrap and this kind of information to a WP_Query without messing-up with other existing query parameters.

Last edited 9 months ago by drzraf (previous) (diff)
Note: See TracTickets for help on using tickets.