I have example code:
<?php
$defaults = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'id',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 0,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 1,
'hierarchical' => 1,
'name' => 'cat',
'id' => 'mySelect',
'class' => 'postform',
'depth' => 0,
'tab_index' => 1,
'taxonomy' => 'category',
'hide_if_empty' => false,
'option_none_value' => -1,
'value_field' => 'name',
'required' => false,
);
wp_dropdown_categories( $defaults )
?>
Html will have like this:
<option class="level-1" value="Name category 1">Name category 1 (38)</option>
How to show term ID beside Name category like this:
<option class="level-1" value="Name category 1">Name category 1 (ID-161) (38)</option>
Thanks for your help
I have example code:
<?php
$defaults = array(
'show_option_all' => '',
'show_option_none' => '',
'orderby' => 'id',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 0,
'child_of' => 0,
'exclude' => '',
'echo' => 1,
'selected' => 1,
'hierarchical' => 1,
'name' => 'cat',
'id' => 'mySelect',
'class' => 'postform',
'depth' => 0,
'tab_index' => 1,
'taxonomy' => 'category',
'hide_if_empty' => false,
'option_none_value' => -1,
'value_field' => 'name',
'required' => false,
);
wp_dropdown_categories( $defaults )
?>
Html will have like this:
<option class="level-1" value="Name category 1">Name category 1 (38)</option>
How to show term ID beside Name category like this:
<option class="level-1" value="Name category 1">Name category 1 (ID-161) (38)</option>
Thanks for your help
Share Improve this question asked Apr 22, 2020 at 11:30 tientruong0810tientruong0810 11 Answer
Reset to default 0You can add a custom hook to the functions.php for that:
function my_add_cat_id($category_name, $category) {
return $category_name ." (ID-".$category->term_id.")";
}
add_filter('list_cats', 'my_add_cat_id', 10,2);