Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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 single_term_title.

$category = single_term_title("", false);

$catid = get_cat_ID( $category );

$category is displaying "Entertainment" for example. But I also need the ID of "Entertainment". How would I go about this?

1 Answer

0 votes
by (106k points)

If you want to get the current category ID of the active page you can use the get_the_category()method below is the code for the same:-

$categories = get_the_category();

$category_id = $categories[0]->cat_ID;

Related questions

+1 vote
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Aug 6, 2019 in Web Technology by Sammy (47.6k points)

Browse Categories

...