Quantcast
Channel: Get current category ID of the active page - Stack Overflow
Browsing latest articles
Browse All 14 View Live

Answer by Sam for Get current category ID of the active page

I tested all these answers and this is the only one which works on all archive page types including posts page.$category_id = get_the_category( get_the_ID());$cat_id =...

View Article



Answer by Hemant Adhikari for Get current category ID of the active page

Here's an efficient method to get category meta data, along with HTML if you want to print it out on the front-end:<?php function custom_get_categories() { $categories = get_the_category();...

View Article

Answer by honk31 for Get current category ID of the active page

if you need the category ID, you would get it via get_query_var, that is capable of retrieving all publicly queryble variables.$category_id = get_query_var('cat');here is an example to get the category...

View Article

Answer by Robert Sinclair for Get current category ID of the active page

Tried above for solutions to find cat ID of a post, but nothing worked, used the following instead:$obj = get_queried_object();$c_id = wp_get_post_categories($obj->ID);

View Article

Answer by Abhijit Patel for Get current category ID of the active page

$cats = wp_get_post_terms( $post->ID, 'product_cat' );foreach($cats as $cat){/*check for category having parent or not except category id=1 which is wordpress default category (Uncategorized)*/...

View Article


Answer by nh-labs for Get current category ID of the active page

I used this for breadcrums in the category template page:$cat_obj = $wp_query->get_queried_object();$thiscat_id = $cat_obj->term_id;$thiscat = get_category($thiscat_id);$parentcat =...

View Article

Answer by Bheru Lal Lohar for Get current category ID of the active page

Alternative - $catID = the_category_ID($echo=false);EDIT: Above function is deprecated please use get_the_category()

View Article

Answer by Shaffe for Get current category ID of the active page

I use the get_queried_object function to get the current category on a category.php template page.$current_category = get_queried_object();Jordan Eldredge is right, get_the_category is not suitable here.

View Article


Answer by Jorge Orpinel Pérez for Get current category ID of the active page

I think some of the above may work but using the get_the_category function seems tricky and may give unexpected results.I think the most direct and simple way to access the cat ID in a category page...

View Article


Answer by Fred K for Get current category ID of the active page

The oldest but fastest way you can use is:$cat_id = get_query_var('cat');

View Article

Answer by Bill for Get current category ID of the active page

I found this question whilst looking for exactly what you asked. Unfortunately you have accepted an incorrect answer. For the sake of other people who are trying to achieve what we were trying to...

View Article

Answer by Ram Mehar Deswal for Get current category ID of the active page

If it is a category page,you can get id of current category by:$category = get_category( get_query_var( 'cat' ) );$cat_id = $category->cat_ID;If you want to get category id of any particular...

View Article

Answer by ash108 for Get current category ID of the active page

You can try using get_the_category():$categories = get_the_category();$category_id = $categories[0]->cat_ID;

View Article


Get current category ID of the active page

Looking to pull the category ID of a specific page in WordPress that is listing all posts using that specific category. Tried the below but not working. I am able to get the category name using...

View Article
Browsing latest articles
Browse All 14 View Live




Latest Images