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
- How can I hide a category from Contributors in the edit/add new post screen?
- WordPress Multiple Category Search
- 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 to use a different domain/subdomain for authors/catagories on single site?
- Delete a specific category when deleting a user
- 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
- Show posts of one category only with Custom Taxonomy on single.php
- Remove “Parent” Selection When Adding/Editing Categories?
- is_archive() content being shown instead of is_category()
- Which php file lists all the post of a category
- Hide post meta data on a specific category
- 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’);?
- Multiple menu items highlighted
- 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 do I add a function on a specific post category?
- Need Category RSS Feed that shows all posts
- 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
- one category template for multiple categories
- Display posts separated by Category in Author’s page
- Different templates for different category tags
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- Updating category template to change how subcategories display
- How can I get categories IDs if multiple categories requested via URI?
- How to rewrite the post URL according to the category?
- Category template to show different categories based on parent
- Sub category templates
- Custom taxonomy template for categories
- Display thumbnails for certain category posts
- Is it possible to remove from default category widget?
- Limit number of posts on a custom category template – breaking pagination
- 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
- Different CSS class by category
- Wrong category nice name is displayed on archive page
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- How to use wp_list_categories with plugin category?
- Using if statement in index.php instead of creating separate template files
- Add Date & Author Meta to Category Archive Page
- Custom css per category and per single post belong in each category
- Displaying year once in category.php [duplicate]
- How to hide widget from certain category
- Category link redirect to custom template page instead of index.php?
- How to differentiate the homepage structure from the category page structure in WordPress template?
- SQL query to get posts from multiple categories but not in a category
- wp_delete_term or wp_delete_category?
- Select posts that match multiple category names, must match all categories listed
- Different header for each category
- Custom post type archive category page results in 404
- Last x Posted Categories?
- Include home page template in specific category template
- separate posts to have (kind of) 2 blogs?
- Output Title of Post’s Current Category
- Include last post date in get_categories loop
- How can I add category variable inside posts?
- problem with filter of custom portfolio categories
- Deleted categories still listed until additional page refresh
- Custom Archive Template for Multiple Categories
- Search Replace Database ONLY for posts of certain category?
- Filter custom taxonomy posts via AJAX
- Adding a category view to a page
- Display Taxonomies in loop with template args
- If it is a top level category show children otherwise show sibling categories
- Most efficient way to have 1 template for parent, 1 template for child categories?
- Category Templates for Post Types not Working
- One category not displaying template updates
- How do I get a single page navigation depending on the previous page?
- Add 1 category more to If_in_category statement
- List all authors by matching custom meta data on a category page
- Template files not working for archives and categories
- Category Template – to be editable from the backend?
- why is the delete option missing from just one category?
- How to prevent page re-sizing for mobile browsers [closed]
- have_posts is empty on category.php
- Custom permalinks structure
- Woocommerce custom taxonomy order