On a category archive, the “queried object” will have what you need.
$cat = get_queried_object();
var_dump($cat->cat_ID);
You can access it by means of get_query_var()
:
$cat = get_query_var('cat');
var_dump($cat);
You can also pull is straight from the $wp_query
global:
var_dump($wp_query->query_vars['cat']);
All of these assume that you are actually on a proper category archive page and that nothing has clobbered or otherwise corrupted the main query.
Related Posts:
- How to display only 3 main categories, separated by commas, since they are marked in the post?
- is_category() function
- Give specific category its own permalink structure
- Create terms when registering taxonomy?
- Add category to custom post type automatically, using category slug
- How do I edit pre_get_post for the category the user is currently in?
- Remove “Category Archives: title” at the top of a category page [duplicate]
- Category Alphabet List Broken
- Display Only One Category
- Display only one result from “get_the_category_list”
- Display empty taxonomy terms with get_terms()
- Connecting WordPress gallery to custom categories (taxonomy)
- Assign an icon to a category post
- How can I show the subcategories content on the parent category page?
- Multi-site or categories?
- Custom Category/Subcategory structure
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Format Brand value in Category view [closed]
- Remove ‘rel’ attributes from the_category() output
- Default category link for a custom category is a broken link
- View the latest created categories
- If statement within PHP echo
- category hierarchy level as a body class – parent cat =1, child cat=2, grandchild=3
- How to show author name only if the post is in a specific category?
- Are Category or Tag Archive Pages Possible?
- 3 Columns, 3 Categories, One Archive, and Pagination
- Possible to make a subdirectory that loops through a single category?
- Archives for each category on WP Multisite
- Update post title with category name after editing a category
- Automatically set default password to all posts in a specific category
- How to Exclude post from a category
- Hiding a Categories content on just the Homepage ‘Posts’?
- Warn me about ‘uncategorized’ posts
- How to change a post category when the ACF datepicker Field is today
- Categories showing page not found
- Send to different single pages by category when multiple categories exist
- Multiple Loops on category.php with pagination on last loop
- How can you change the permalink for pages?
- How to select category on if function
- how to wordpress When I click on the category link, subcategories appear
- woocommerce related products by specific categories [closed]
- Problem with different query loops (and “main loop”) on category template page!
- Show posts in “image” format when viewed in category page, but with comments in blog
- Change the name Category – Not change category name
- How to change the order of the subcategory and category in a post?
- Properly setting up a feed
- About title on a page
- custom page for custom Taxonomy
- Why get_category() function is not working not working when embedded in a page?
- How to remove one specific category (uncategorized) from post permalinks
- Combining a meta_query with a category filter
- Theme for subcategories
- How to link a PDF file to a category URL
- How to schedule categories?
- Template for product-category page [closed]
- what file I need to create to work date archive links?
- multiple values in an array for category__and does not work with WP_Query
- Category view with contents of [gallery]s shown
- Assigning certain pages or posts to use the template of the parent page or category
- How can I include custom category and tag base in template files?
- How to get posts using category slug in ClassiPress?
- query_post problem
- Assign author to category and not only posts
- Add properties to term object
- How to fetch common posts from two feeds?
- Display all Categories
- custom wp_list_categories in single.php
- How to target all woocommerce categories that don’t have any subcategories in them?
- Is this process OK to replace URL structure?
- echo $category[0]-> cat_name; shows only one category name
- How can i echo next and previous custom category from a Taxonomy
- Change post category within pre_get_posts
- How to check a category checkbox using JavaScript
- Ajax Category add doesn’t update the list table custom column
- Need help to structure our a complex hierarchy
- global categories – Share specific categories in wordpress multisite
- Question About Messing With Category Pages and Descriptions
- how to get postmeta info based on multiple categories?
- create post with main category and other categories from admin panel
- How Can Hide Define Category in Post Contents?
- How to auto update post title and slug with category name when post status is updated
- get_posts – require all categories
- 404 error when i try to search by category or by tag
- Choosing different templates for categories
- List Terms by category
- Add advertising box to a specific category page
- How do you add Author and date Published on Category Pages?
- hierarchical taxonomy in permalinks? using same slug
- WordPress Numeric Pagination with Query String [duplicate]
- Changing Permalinks for Category Pages Only
- Twenty Eleven Theme [duplicate]
- display certain category on custom template page
- Get post by Category in custom template
- Ajax call activate after submit in edit-tags.php page
- List products from current category
- Assign a category by user and customize the edit-tags.php?taxonomy=category page
- comments_number fails to print
- How to show posts of a specific category
- How to show child category name & post from it’s parent [closed]
- Open everything in new tab