Skip to content

Commit

Permalink
Query Filters: Add taxonomy term counts
Browse files Browse the repository at this point in the history
  • Loading branch information
renintw committed Oct 9, 2023
1 parent b11aa4d commit 1a365ad
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions source/wp-content/themes/wporg-showcase-2022/inc/block-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ function ( $a, $b ) {
_n( 'Popular tags <span>%s</span>', 'Popular tags <span>%s</span>', $count, 'wporg' ),
$count
);
$option_labels = array_map(
function( $name, $count ) {
return $name . " ($count)";
},
wp_list_pluck( $tags, 'name' ),
wp_list_pluck( $tags, 'count' )
);
return array(
'label' => $label,
'title' => __( 'Popular tags', 'wporg' ),
'key' => 'tag',
'action' => home_url( '/archives/' ),
'options' => array_combine( wp_list_pluck( $tags, 'slug' ), wp_list_pluck( $tags, 'name' ) ),
'options' => array_combine( wp_list_pluck( $tags, 'slug' ), $option_labels ),
'selected' => $selected,
);
}
Expand All @@ -101,12 +108,20 @@ function get_flavor_options( $options ) {
_n( 'Flavors <span>%s</span>', 'Flavors <span>%s</span>', $count, 'wporg' ),
$count
);
$option_labels = array_map(
function( $name, $count ) {
return $name . " ($count)";
},
wp_list_pluck( $flavors, 'name' ),
wp_list_pluck( $flavors, 'count' )
);

return array(
'label' => $label,
'title' => __( 'Flavors', 'wporg' ),
'key' => 'flavor',
'action' => home_url( '/archives/' ),
'options' => array_combine( wp_list_pluck( $flavors, 'slug' ), wp_list_pluck( $flavors, 'name' ) ),
'options' => array_combine( wp_list_pluck( $flavors, 'slug' ), $option_labels ),
'selected' => $selected,
);
}
Expand Down Expand Up @@ -147,12 +162,19 @@ function get_category_options( $options ) {
_n( 'Categories <span>%s</span>', 'Categories <span>%s</span>', $count, 'wporg' ),
$count
);
$option_labels = array_map(
function( $name, $count ) {
return $name . " ($count)";
},
wp_list_pluck( $categories, 'name' ),
wp_list_pluck( $categories, 'count' )
);
return array(
'label' => $label,
'title' => __( 'Categories', 'wporg' ),
'key' => 'cat',
'action' => home_url( '/archives/' ),
'options' => array_combine( wp_list_pluck( $categories, 'term_id' ), wp_list_pluck( $categories, 'name' ) ),
'options' => array_combine( wp_list_pluck( $categories, 'term_id' ), $option_labels ),
'selected' => $selected,
);
}
Expand Down

0 comments on commit 1a365ad

Please sign in to comment.