0

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

0

You 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);
| improve this answer | |
  • Thanks for your help. It work for me. Thank you again! – tientruong0810 May 7 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.