Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working with a couple of plugins that ask for a list of category IDs to include/exclude.

When I go to the categories section and select "Edit" I don't see an ID field listed on the page, though I see all the other details. Since I will be relaying this information onto other users, how can I find the category ID for them?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

there are some plugins that reveal the ID's on the admin side like WP Show IDs

and by code like this:

                  //as dropdown
$categories=  get_categories(array('hide_empty' => 0,'taxonomy' => 'category')); 
 echo '<select>';
  foreach ($categories as $category) {

    $option = '<option value="'.$category->category_id.'">';
    $option .= $category->cat_name;
    $option .= '</option>';
    echo $option;
  }
  echo '</select>';

  //or just print the categories names  by ids like this

  $categories=  get_categories(array('hide_empty' => 0,'taxonomy' => 'category')); 

  foreach ($categories as $category) {

    echo $category->category_id;
    echo $category->cat_name;

    }
share|improve this answer
    
That plugin is perfect! Since the end user isn't tech saavy, I can simply add it to the site. Thanks! –  Dillie-O Jan 18 '11 at 16:47
    
glad to help, any time :) –  Bainternet Jan 18 '11 at 17:11
add comment

Showing the IDs is pretty simple, you need to hook onto the table heading and columns for that taxonomy's management page.

I previously discussed this in a support topic here.

First hook onto the taxonomy table heading and add the new heading into the columns array.

function category_id_head( $columns ) {
    $columns['term_id'] = __('ID');
    return $columns;
}

add_filter( 'manage_edit-category_columns', 'category_id_head' );

Then hook onto the taxonomy table rows and output the term IDs.

function category_id_row( $output, $column, $term_id ){
    if( $column != 'term_id')
        return $output;
    return $term_id;
}

add_filter( 'manage_category_custom_column', 'category_id_row', 10, 3 );

You can of course always use a plugin, but for such a small amount of code that seems a bit silly.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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