get_ancestors()
returns an array containing the parents of any given object.
This example has two categories. The parent with the id of 447 and the child with a id of 448 and returns the a category hierarchy (with IDs):
get_ancestors( 448, 'category' );
returns:
Array
(
[0] => 447
)
get_ancestors Codex Page
Related Posts:
- How to get permalinks with category base working with sub-categories
- WP 3.9 TinyMCE no longer loads on category description editor
- Change Gutenberg category checkboxes to radios
- Checklist of selected categories
- Admin Panel – Disable Moving Selected Terms To Top of Metabox
- How to make custom taxonomy check boxes like ‘Categories’
- How to create non-unique sub-category slugs?
- Loop with Dynamic Categories
- Automatically select categories on new post based on GET value
- So how to redirect category to a page of the same name if it exists?
- I want to create a posts widget and be able to select categories
- get only sub category ID
- Display categories inline
- Get tags specific category
- show posts names and links in the sidebar list as categories child
- Add a specific category at a specific place to the menu that uses wp_list_pages
- Filter posts under multiple categories?
- How to show Sub Categories on Categories page?
- How would I go about pulling the most popular (most used) categories?
- New Theme creation
- Custom order categories in admin dashboard
- multiple categories and breadcrumbs problem
- Editing Category Pages
- List subcategories of a specific product category (adapting from posts to products taxonomy)
- Get all subcategories and related posts
- How to get data about category in category.php
- Display tags from specific category in select fields
- Offline WordPress Application
- Add Image Size for one Media Category Only
- woocommerce product category tabs [closed]
- Taxonomy name repeating when showing 2 posts from each category
- How to change category and year archive permalinks/rewrite rules?
- The Category page shows all the posts, without differentiating by categories
- New Categories Not Shown In the Post Edit Page
- Different templates for different category tags
- Category param redirect to post type archive
- batch adding posts to a category based on matching regex for title with SQL
- Place category Base URL at the end
- Listing Texts of Which Custom Field is Null
- How to set a filter by category within a customised page
- Post Count for Categories, however not to calculate a total
- Flat category URLs but retaining hierarchy?
- Creating a custom feed for categories that includes the first post’s featured image
- echo category description in single.php
- Get categories without post
- Hide the word ‘category’ from my permalinks
- How to automatically check multiple categories on new post
- School & class blogs – renaming/archiving post categories?
- How to modify default category widget list display?
- How do I get the parent category if I know the child category?
- List just subcategory and products of active category page in Woocommerce
- Custom Meta Box (SELECT2) Not Saving Taxonomy Terms
- Force category choice before creating new post
- Listing posts under a category by date
- Display content from a specific category using cat ID not working
- Deleting a category from WordPress admin does it remove it completely from the database?
- How to modify the “View all posts in category” title attribute
- Show post categories
- Exclude categories by ID
- Add description to categories menu in admin
- filter a loop base on specific category
- Display Sub-categories or Child Pages of Parent Cat/Page?
- How to check if a categoryID exists in a theme options page
- How to display product categories and number of sales on WooCommerce
- Display one category and its suncategories
- How to differentiate the homepage structure from the category page structure in WordPress template?
- Placing category specific banner/html at top of respective category pages
- Get parent category field from child category [closed]
- Custom sidebar isn’t showing up on sub-category posts
- Can a Woocommerce product category URL contain “&”?
- How can I display all products from all categories on one page with woocommerce?
- get_the_category return empty inside loop
- Possible to make get_categories() hide_empty attribute honor excludes from post query?
- Unable to create pagination for Category.php
- Function add class to second menu specific items if the page has a certain category
- Posts says they are uncategorized but they are not
- How to call Primary Category for WordPress Woocommerce
- Meta Box: display single image on an archive-template
- Search Replace Database ONLY for posts of certain category?
- Categories Help and video uploads
- Display only children of custom hierachial taxonomy
- Read More showing only on first post
- Filtered post assigned to categories
- Allow a user to ‘subscribe’ to different post categories?
- How to exclude a specific categogy from a custom page template
- If on Category Page add “active” class?
- Transfering static site to wordpress and retaining category by month paginations
- Category Templates for Post Types not Working
- Change category base based on category
- Show only one category in main query, issues on tag page
- Bringing Ajax Loading Feature on Category Pages
- Need help with category page customization meeting certain condition
- How do i add custom post types to this query?
- Show category-ID in custom category-list
- Dynamically Adding Category Specific Content To Specific Category & Subcategory Pages
- Structure with category setting
- chose category in plugin
- Do not show all post from all categories, just show posts from category in current loop
- How to prevent page re-sizing for mobile browsers [closed]
- Images as Categories