From e894711ab0290a09c4947b0868b2e5ae6b8e0e9e Mon Sep 17 00:00:00 2001 From: kokiddp Date: Fri, 24 Jun 2022 11:40:31 +0200 Subject: [PATCH] add checkboxes filter to admin filters --- src/PostTypeAdmin.php | 90 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/src/PostTypeAdmin.php b/src/PostTypeAdmin.php index a875bba..85c2498 100644 --- a/src/PostTypeAdmin.php +++ b/src/PostTypeAdmin.php @@ -303,22 +303,80 @@ public function filters(): void { esc_html( $tax->labels->filter_by ?? $tax->labels->singular_name ) ); - # Output the dropdown: - wp_dropdown_categories( - [ - 'show_option_all' => $filter['title'], - 'hide_empty' => false, - 'hide_if_empty' => true, - 'hierarchical' => true, - 'show_count' => false, - 'orderby' => 'name', - 'selected_cats' => $tax->query_var ? get_query_var( $tax->query_var ) : [], - 'id' => $id, - 'name' => (string) $tax->query_var, - 'taxonomy' => $filter['taxonomy'], - 'walker' => $walker, - ] - ); + if ( isset( $filter['type'] ) ) { + if ( $filter['type'] == 'checkboxes' ) { + ?> +
+ + +
+ 'slug', + ] + ); + + # Output the dropdown: + wp_dropdown_categories( + [ + 'show_option_all' => $filter['title'], + 'hide_empty' => true, + 'hide_if_empty' => true, + 'hierarchical' => true, + 'show_count' => false, + 'orderby' => 'name', + 'selected_cats' => $tax->query_var ? get_query_var( $tax->query_var ) : [], + 'id' => $id, + 'name' => (string) $tax->query_var, + 'taxonomy' => $filter['taxonomy'], + 'walker' => $walker, + ] + ); + } + } + else { + $walker = new Walker\Dropdown( + [ + 'field' => 'slug', + ] + ); + + # Output the dropdown: + wp_dropdown_categories( + [ + 'show_option_all' => $filter['title'], + 'hide_empty' => true, + 'hide_if_empty' => true, + 'hierarchical' => true, + 'show_count' => false, + 'orderby' => 'name', + 'selected_cats' => $tax->query_var ? get_query_var( $tax->query_var ) : [], + 'id' => $id, + 'name' => (string) $tax->query_var, + 'taxonomy' => $filter['taxonomy'], + 'walker' => $walker, + ] + ); + } } elseif ( isset( $filter['meta_key'] ) ) { # If we haven't specified a title, generate one from the meta key: if ( ! isset( $filter['title'] ) ) {