get_the_category retrieve array of post categories.
This tag may be used outside the loop by passing a post id
as the parameter.
The syntax is
$categories = get_the_category( $post_id ); // Outside the loop
// OR
$categories = get_the_category( ); // Inside the loop
Note: This function only returns results from the default “category” taxonomy. For custom taxonomies use get_the_terms() .
$categories = get_the_terms( $post_id, 'taxonomy' );
I hope this may help.
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
- Display all posts in current category
- Looking to exclude blog posts from category Previous/Next buttons
- How to display related posts from parent category
- How can I set custom order use this function
- Put a link to a category round a hard coded A HREF
- Check if Product is in a Specific Category in Functions.php
- How to exclude specific category from the get_the_category(); array
- Category Thumbnail Display – How to display ONLY the main Category
- combine Code 1 with Code 2
- Creating a related post section based on similar categories
- Swapping wp_dropdown_categories function with wp_category_checklist
- Proper syntax or method for keeping url in modified isotope / category links
- Issue adding sub category programmatically
- 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
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- 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
- how to show only specific category for a template
- Creating sub-categories via php
- Define specific category name in PHP
- Edit the_category (); for a hierarchical display
- 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]
- Displaying posts based on category
- How do I remove a category from a wordpress loop>
- Get categories names as an array to use it in theme settings
- How to get the last category name of a child category?
- 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
- 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
- Admin backend, show post from a category and exclude the posts from subcategories
- 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
- Rearrange get_categories array compared to another array
- 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?
- Display all categories (with link) of custom post type – WordPress
- 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)
- Exclude a category ID from the following function