After some trial and error I managed to come up with the following:
<?php if (is_category( )) {
$cat = get_query_var('cat');
$thiscat = get_category ($cat);
$parent = $thiscat->parent;
if ($parent != '') {
wp_list_categories( array(
'child_of' => $parent,
'exclude' => $cat
) );
}
else {
wp_list_categories( array(
'child_of' => $cat
) );
}
} ?>
I’m not sure if this is the most efficient method but it does work.
Related Posts:
- Get the children of the parent category
- How to remove the term “category” from category pagination?
- How to add featured image for category (without a plugin)?
- Category archive by year with permalink support /category/YYYY
- Force WordPress to Show Pages Instead of Category
- How do I get the category URL from get_the_category?
- Default WP Gallery – show only galleries of a certain category
- Exclude sub category posts from category display
- Is there a way to remove categories in bulk?
- Is it possible to put next and previous category links?
- Custom category template pagination problem
- Deleting All tags except categories Wp database
- Action hooks returning old category instead of new category
- Category checkboxes in upload modal
- Getting category before saving post
- How do I change the sql query for wp_get_archive()
- How to mass-insert categories?
- How to put enctype=”multipart/form-data” in categories form?
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Custom WP_Query for current category (in category.php)?
- Why is get_the_category() saying that I have two categories?
- Custom sidebar on category pages
- Insert Into Sub-child Menu
- How do I get the category slug from wp_dropdown_categories
- Change the category of all posts in it
- How to display widgets inside a page content without a plugin?
- shop page with all categories with paginate
- Get Tags specific to Category using WooCommerce plugin
- Giving wp_list_categories the class of the category
- How to filter out Categories for specific post types on WordPress Admin?
- List categories with posts
- Pagination not visible on woocommerce’s category page
- Category archive rewrite rule to include category/subcategory?
- How can I automatically display a visual archive of subcategory posts [and thumbnails] separate from Parent category?
- The default code for “posts_nav_link” on category.php isn’t working
- Woocommerce custom category pages
- Custom sub taxonomy order by
- Hide uncategorized when no category set
- wp_list_categories set order manually?
- Refine/Filter the Search Results by Category
- Putting a Category of posts under a Page
- change recent posts based on category
- Have multiple category queries from the URL been fixed yet?
- Why is it so hard to show the URL of the current category and how to do it?
- Where and when does WordPress invoke routes
- Getting category URL with hyphens, not spaces
- How can I change the tooltip in the_category?
- Category.php loads first before page.php?
- How to get Next/previous_post_link to go through articles in top parent category
- What’s wrong with my wp database query?
- Conditional loop for category
- Fix Warnings that shouldn’t be necessary to fix
- how to get correct category of a post in case of multiple categories?
- Show button only for certain Woocommerce Product Categories
- Thumbnail for categories / taxonomies plugin?
- Pagination for query_posts();
- echo get_post_meta of all post in a category to fill up a select field
- get listed category’s id?
- Length of Category Names
- Notice: Undefined variable: category_id
- Is it possible to create an alias/custom taxonomy for a category name?
- I need to exclude from a query a category and a few custom taxonomies
- Multiple category columns and post counting list in wordpress Homepage
- wp_insert_link not working
- Check for parent category
- Showing different posts on category pages
- add current-cat class to single post page
- Problem with wp_create_category
- How to exclude certain categories showing in Gutenberg?
- Problem with pagination block in Gutenberg
- Product category display in tabs
- Sending all categories associated with a post to Google Ad Manager for use with .setTargeting
- Pull in an “Include” file based on a WordPress Category ID
- How to redirect to category page if page does not exists?
- Sort categories by custom field in WordPress admin
- Why is URL Slug Saving Differently From How It’s Been Defined?
- Related to genre and category
- Get permalink to latest post in category
- How to noindex, follow a specific category wordpress?
- get taxonomy list in a page in the wordpress
- How to load terms of a custom taxonomy of a product in woocommerce cart page
- Category and tag urls return 404 error
- Removin /page/2 from pagination
- get parent_category class in loop
- Group Posts by First Letter of Title categories
- Display all of a post’s categories except the current category
- Alphabetize all but one category
- How to make 10 post of one category
- How to create a category or tag available exclusively to the admins and not to the users?
- Printing direct descendants of a category with WP_Query
- wordpress category.php query for featured news item, broken pagination and repeating posts
- Listing category
- List all authors by matching custom meta data on a category page
- Page view: Sorted by categories
- Anyway to hide a Category in the Categories section when adding/editing a post in WP Admin?
- Showing one post from each category, paged?
- Custom permalinks structure
- Weird html output of single_cat_title – is not inside of the html element?
- Limit authors on specific catogories
- how do I exclude a category foreach