get_categories()
gives you an array of WP_Term
objects, which has the parent
property. This contains the ID of the parent category. Inside your loop you can do a simple comparison to see, if the current iteration category has the specific parent category’s ID or not, and if it does, skip it.
$parent_id = 123; // change to actual term id
foreach( $categories as $category ) {
if ( $parent_id === $category->parent ) {
continue;
}
// rest of the code...
}
Related Posts:
- How to show all posts of the category in wordpress?
- Filtering a custom post type by custom taxonomy in archive template
- Why are posts from custom post type not displayed in “category” archive?
- Get category id from post id of a custom post type
- Displaying category archive of custom post types
- How to let custom post type posts show in standard post archive (like in homepage)?
- Regex problem in an add_rewrite_rule
- How to show related posts by category or custom post type?
- Structuring a product catalogue in WordPress [closed]
- get_categories for custom post type and filter by custom taxonomy (brand) and list child categories of a defined category
- Slug for standard post post_type
- Category page only displaying the posts from a custom type
- Display types of posts in edit.php instead of All, Published, Scheduled and Draft
- custom taxonomy archive by year
- Custom Taxonomy – Tags Metabox is showing instead of Categories
- How to get the post type from a category id?
- CPT Archive with core Category
- Custom Post Type Archive Page Filtering
- Getting posts under the custom post type ui category
- Show custom post type filtered by category
- Showing posts from different categories and from custom post type
- Add custom post type settings to wordress default posts
- Problem with displaying posts in the CPT category
- Set a checkmark in a category based on a URL-parameter
- Get the category from custom post type
- Custom Post Slug same as Parents Category Slug
- How can I show 1 featured post in a styled element, and the next few below differently styled
- WP the_posts() on single-cars.php get category link
- Create new custom post and post category of same name
- Archieve.php not loading for custom post type
- multiple custom post type on category page
- Custom post types and ‘new WP_Query’
- How to Display Posts From Category Within a Custom Taxonomy?
- Showing custom post type categories in the menu
- Stores category posts in an array
- Restrict category access to specific users/groups. Author always has access
- Post Query not working
- Use post in multiple places on a page with multiple posts
- Archive Template being used instead of Category Template for Custom Post Type
- Menu’s breaking, now showing all page links on site
- Am I mixing up the concept of posts pages and categories?
- Advanced archive url structure (category, tag and date)
- How to achieve a multi-taxomony layout with posts?
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Post category behave like a Post in back office menu
- Save data is post using php front end
- Custom WordPress theme not displaying posts from category
- How to show posts of the same category on a page?
- How to manage a dynamic multi-level page hierearchy system?
- Custom Post By Category
- Adding Custom Post Types to category/tag/author archives breaks header content
- Custom category taxonomy – archive page not showing up
- Change Custom Post Type to Post + Category
- Only show current category post
- How can I generate a list of post-type specific categories?
- Custom Post type archives / categories give 404
- Post Editor: display categories from current post type taxonomy only?
- archive.php can’t find categorized posts
- Custom Post Type used for FAQs Accordion
- Display all post types together
- How can I set up the URL for a category archive for a custom post type?
- Categories in custom post types
- How to make a list of posts displaying them 5 by 5 with a “next posts” link?
- Stop header code from showing in category page?
- show only one category posts in admin
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Separate archive template to show posts and CPT by same category/taxonomy
- Display posts of only a certain category in WP Admin section?
- WordPress Custom Post Type Archive, filter by category and get pagination working
- Archive page for taxonomy terms
- How to show CPTs in term archive
- How to create custom boxes with text inside?
- How to change post featured image using a custom field of category?
- How to add post_type=value when editing that post type in the WordPress admin?
- Custom template page with custom archives listing by user
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Open Custom Post Type as PDF
- Using The REST API How To Pull All Custom Posts?
- Group posts by custom post type
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- How can i change the output of posts_nav_link();
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Display all posts in main category and 1 subcategory
- Replace li Items with divs with classes
- showing custom post types of a certain category only
- Get posts from a custom post type by child categories of a parent category
- Linking to the most recent post in a Custom Post Type
- Root slug of taxonomy returning 404
- Show the same Article Available in Other Categories
- Show category ID on custom post type
- How to modify archive query with pre_get_posts to append CPTs?
- How can I auto-assign a CPT post to category in a custom taxonomy when published?
- get the custom post type title/name
- Storing posts from query and accessing later via AJAX call
- If post has custom field then display css-class
- get_posts() with custom post type does not work outside page.php
- Get archive post type name
- Posts from all the categories are being displayed instead of particular category
- Display only one post each WEEK
- Get parent categories of custom post type