It returns an array because Posts can have multiple categories. You just need to get the item from the array whose name you want, ($queried_object[0]
for the first one), then get the value out of that the same way you would any PHP object:
$name = $queried_object[0]->name;
You should probably include some checks to make sure the post has a category before attempting to use the array or object like this:
$categories = get_the_category( get_queried_object_id() );
if ( ! empty( $categories ) ) {
$category = $categories[0];
$name = $category->name;
}
Related Posts:
- What does the token %1$s in WordPress represent [closed]
- exclude multiple terms using get_terms() function
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Archive listing of posts by publish year (multiple years)
- Add custom field to attachments in a specific category
- How to Remove Parents Category Permalink from Posts
- Looking to exclude blog posts from category Previous/Next buttons
- List all categories but exclude current post category on single post page
- Put a link to a category round a hard coded A HREF
- How to exclude specific category from the get_the_category(); array
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- Where do posts get the sidebar from?
- combine Code 1 with Code 2
- get post based on category chosen in drop down – The ajax method
- Creating a related post section based on similar categories
- Proper syntax or method for keeping url in modified isotope / category links
- Issue adding sub category programmatically
- how do I get a specific post from a post with a subcategory in WP
- WP grandchild categories in nested ul li
- Grab posts by multiple categories
- selected option if current category is the value
- get_template_part based upon post’s category
- how to save selected option in variable for rest api category filter
- Alert Bar section within WP loop is displaying even though there are no posts
- Different post styles depending on category
- Display category name only once inside loop
- Dilemma of Populating all the categories in a drop down list
- Creating sub-categories via php
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- JSON REST API WordPress only showing first 10 categories
- Category title output before opening title tag
- Include Parent Term in wp_list_categories
- How to array only one key from another array
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Get all categories post is not in
- How do I remove a category from a wordpress loop>
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- How to get category name or ID by post?
- How to hide posts of a specific custom category in WordPress?
- Add new post in existing categories using wp_insert_post
- How to change logo by category
- Problem with custom loop and wp_list_pluck [closed]
- Listing titles and custom fields of entries within subcategories
- random display categories – change url
- Output category list inside array
- Do not duplicate posts with multiple categories in multiple loops
- Removing sidebar on category pages
- WooCommerce: Display product categories to make IF statement
- Trying To Get Child Categories To Show, Issue With foreach Loop
- Define category ID using get_post_meta
- How To Pass Array To get_the_category_by_ID() and Get An Array Back?
- Adding wp_list_categories to a specific div that was appended using jQuery
- Counting number of posts in multiple (sub)categories using shortcode
- I need to display posts in subcategory beside posts in main category
- Add Custom Category Description When Empty
- Order category posts by last word of custom field
- How do I edit the terms output args or array data?
- Add a product category to a specific product via a button
- Change category thumbnail size
- Get nice name of category from slug (remove dashes of category)
- admin panel – How to remove “delete” button from category editing page
- Get parent category name when only child category is applied to a product
- Multiple Tag Filtering
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- How to Link to category titles if it is in the single post content?
- Polylang and template files
- How can i show specific Category List?
- Notice: Undefined variable
- How to show category just on specific pages?
- Show subcategory name selected in specific category woocoommerce
- How to filter specific element of an array in wordpress/php?
- Exclude category and post from loop in custom category.php
- Exclude a category slug on pagination
- Custom content using in_category
- PHP drop down menu for my get_category child of
- PHP get_category() function redeclared
- Need Quick Help With Product Category Page
- List categories assigned to a post
- Unable to get Post Category Name and URL
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- Rearrange get_categories array compared to another array
- Search in particular category in wordpress
- Query seems to be duplicated
- Top menu disapears in Category Pages when filtering using ACF
- Trying to see if page is category or single and displaying title with appropriate heading tag
- !in_array doesnt recognize category
- How to change links in the 3 main categories, on widget category, to a javascript function call
- Remove the_content From Loop
- Category List in Theme Options Page
- how to set category name for a post
- category & sub category order issues in wordpress
- Fix incorrect related posts code snippet
- Display a list of posts corresponding to a category
- Product Category Page in Full Width
- How to create categories out of a list of words?
- Is there a way of displaying related posts from lowest hyrachical order (lowest child category to parent category)
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Get category name of current post (CPT UI)
- How to limit number of posts in the certain category and exclude the oldest post automatically