category_name
expects a category slug, albeit the name of the parameter.
get_the_category
should be used either with an ID or inside the loop – it returns the categories for the given/current post. But even if that worked, you’ll get an array of WP_Term objects – cat_name
is not a property. User ->name
to get the name, or ->slug
to get the slug.
If you know the category ID or slug, you can simply use get_term_by, e.g.
if($term = get_term_by("id", $id, "category")) {
// set your arguments for WP_Query
$args["cat"] = $term->term_id;
}
Related Posts:
- Create single.php for specific category by category id
- Apply custom category template to subcategories
- I would like to feature a tip on the homepage
- Show posts from all categories
- Getting page/category content to show up in my custom page template
- Gutenberg editor add a custom category as wrapper for custom blocks
- How can I hide a category from Contributors in the edit/add new post screen?
- WordPress Multiple Category Search
- How to remove categories filter from wordpress admin?
- Decreasing the Memory Consumption of a WordPress Site?
- Preventing index.php?category_name=something from redirecting
- Make all subcategories use the template of its category parent?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive
- How can I select a primary category?
- how to use a different domain/subdomain for authors/catagories on single site?
- Deleting default category in wordpress
- Delete a specific category when deleting a user
- Different templates for parent and children categories/taxonomies
- How to list child categories in custom category template?
- Trash bin for categories
- How to set up sub-categories for author pages?
- View category in the preview of Theme Customizer
- Display only deepest category on a single post?
- One WordPress Install, Two Categories. Each Category Gets a Domain
- How do I set a specific template for sub-categories?
- Block multiple categories from Blog
- Exclude a category from the filed under list only on some templates
- How to have a static category/author page?
- Show posts of one category only with Custom Taxonomy on single.php
- Save metabox checkboxes values to custom content type
- Select category in custom query
- Remove “Parent” Selection When Adding/Editing Categories?
- is_archive() content being shown instead of is_category()
- Order Taxonomy Term by date created
- How to override Category rendering mechanism
- How to control template resolution if both Author and Category filter in place?
- Which php file lists all the post of a category
- Hide post meta data on a specific category
- Format Brand value in Category view [closed]
- Add custom taxonomy under the category title
- How to show in search results posts with a particular tag in a particular category?
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Remove ‘rel’ attributes from the_category() output
- Custom page for WooCommerce’s /product-category/
- Multiple menu items highlighted
- Code to pull in a PHP file named after the category ID
- in_category() works in single.php but not in page.php?
- Use a wordpress page to display a certain category
- Exclude category from Tag Template
- How to view WordPress’ default category IDs?
- Multiple Category Search
- How to make a Thumbnails Mosaic
- How do I add a function on a specific post category?
- Are Category or Tag Archive Pages Possible?
- Possible to make a subdirectory that loops through a single category?
- Need Category RSS Feed that shows all posts
- WooCommerce IF statements not working
- Set a them for all subset of category
- How to customize category template?
- Category-slug.php not being used
- How to display only posts assigned to a particular, isolated, subcategory
- How would I go about adding custom header images per category?
- Highlight wp_nav_menu when category is selected
- Archive.php filtered by pre-determined category
- Automatically exclude categories from metabox based on title
- one category template for multiple categories
- Display posts separated by Category in Author’s page
- Different templates for different category tags
- The default code for “posts_nav_link” on category.php isn’t working
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Only one post is showing on category page, why?
- How to organize custom categories for filtering and selecting
- Updating category template to change how subcategories display
- Filtering *out* a taxonomy from the admin post list
- Categories overview that links to page displaying posts
- How can I get categories IDs if multiple categories requested via URI?
- How to rewrite the post URL according to the category?
- How to build a simple nav system of custom post type categories and its posts?
- Category template to show different categories based on parent
- Does “show_option_all” in wp_list_categories do anything?
- How can I improve this taxonomy treating approach?
- Sub category templates
- Custom taxonomy template for categories
- how to show only specific category for a template
- How to insert category list into post creation page, and retrieve chosen categories?
- Display thumbnails for certain category posts
- Keyword search in multiple categories
- Is it possible to remove from default category widget?
- How to customize my category pages
- Limit number of posts on a custom category template – breaking pagination
- How to make the ‘delete’ button inactive on some categories?
- Two columns in homepage each with one category
- How can I display the number of post associated to a category in Twig/Timber WordPress? [closed]
- Is it possible to have a template that works on multiple categories where the link address contains the specific category?
- Multiple selection for wordpress widget
- Custom template for sub-sub-categories
- Different CSS class by category
- how to nest specific category thumbnails inside different containers
- What Must to Display the “mysite.com/category” URL?
- Wrong category nice name is displayed on archive page