How to Find WordPress Category ID in 3 Easy & Quick Options

How to find a WordPress Category IDWhen creating WordPress themes, you may want to manipulate the data displayed in a WordPress category for different layouts. There are several ways you can find a WordPress category ID but the easiest way is through the dashboard. WordPress category ID helps WordPress theme developer to manipulate and display the category data in various ways. It’s also helpful when you want to restrict the display of content from certain categories.

The category ID just like the page ID is normally displayed on the category page as well as the category URL. If you are also searching for post ID, you can follow this tutorial I wrote on how to find WordPress Page or Post ID.

Finding the ID of a Category in WordPress

In this quick tutorial, I will highlight the various ways you can easily and quickly find the ID of a category in WordPress.  The following are the steps you should take to find the ID.

  1. Log in to your WordPress site dashboard
  2. Under posts click on Categories to open the category page
  3. Choose the category you want to find the category ID
  4. Hover on the category’s edit link and you will see the URL at the bottom with the category ID
  5. Alternatively, open the category by clicking on it.
  6. Check the category ID from the page URL

Log in and Go to Category Page 

You should begin by logging in to your WordPress site and navigate to the posts categories page as shown on the image below:get category id on category page

Choose the Category

Select the category that we want to get the ID like in this example I have selected the ‘best plugins’ category. After selecting the category; hover the edit link as shown in the image below and you should see the page permalink appear at the bottom.

How to find a WordPress Category ID

This permalink has the category ID as shown above, like in this case the ID is 662.

Alternative: Open the Category

You can open the category by clicking on the category title and under the URL you will see the Category ID as shown in the image below:

How to find a WordPress Category ID

Find Category ID using a Plugin

You can also use a plugin like Reveal IDs that shows the page and category IDs. To use the plugin install it from WordPress repository:How to find a WordPress Category ID

Activate the plugin and go back to the category page and you should see a new column with the category ID as shown in the image below:How to find a WordPress Category ID

The reveal IDs plugin is the easiest way when you want to find ID for multiple categories without opening each of these categories.

Find Categories IDs of a Post by Post ID 

You can also use a function that retrieves all categories associated with a post and loops through the categories to display the data specifically the category IDs for each of these categories.  In this case, you should use the wp_get_post_categories function.

function get_the_categories_of_a_post(){

 global $post;

 $post_categories = wp_get_post_categories( $post->ID );
 $cats = array();

  foreach($post_categories as $c){
      $cat = get_category( $c );

      $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
 
      echo $cat->term_id;

   }

}

Get Current Category ID of the Active Page

To get the current category ID of the current page you can use the get_the_category function. You can use the following code to get the category ID

$categories = get_the_category();
$category_id = $categories[0]->cat_ID;

 Conclusion

With these three options, you can easily and quickly find the  ID of any WordPress category. The category ID can be used for various WordPress template development.

You can also get the specific page category as outlined in the last section above using the get_the_category() function. I hope you find this article useful, you can also get in touch with me for more help on any WordPress or web development issue.

Comments are closed.