get_the_terms()
gives you an array of WP_Term objects. The object has parent
(int) property, which tells you, if the term is a child and has a parent term or not.
This means that in your loop you can skip child terms with a simple if
statement.
foreach ($terms as $term) {
// Is it a child term?
if ( $term->parent ) {
continue;
}
// code...
}
Related Posts:
- Custom taxonomy: same terms, but for different years
- get_terms return errors
- How to show only Standard Format post in my custom taxonomy page -wordpress 3.8.1
- Reproducing hierarchical list output from wp_list_categories(), using get_categories()
- Fast way to add countries as a custom taxonomy term?
- Is there a filter hook that I can use to change how taxonomy term names are displayed?
- How to Register and Display Widget for Custom taxonomy
- Show Custom Taxonomy Slug(s)?
- Custom Taxonomy Archive not displaying entries
- Exclude custom taxonomy tag from loop
- Hide custom field if empty
- Filter posts by custom taxonomy terms
- Function to remove archive sidebar for custom taxonomy?
- Automatically check parents (in a taxonomy) when child is selected
- How to add textarea field to taxonomy (tag)?
- How can I get the custom post type assigned to a current custom taxonomy for query?
- wp_query get post custom taxonomy in search.php
- How to get every custom taxonomy names and urls?
- Get Custom Taxonomy Terms by Date
- Display specific Taxonomy Term from Custom Post Type
- Semi complicated custom taxonomy question
- Get wordpress taxonomy slug name(s) to use as div class
- How do I list custom taxonomy terms with the links?
- Echo the Last Child Taxonomy only (not parents)?
- How to query term_id of a Custom Taxonomy by name
- wp_insert_post custom taxonomy multiple Category not added
- query variables for custom taxonomies
- If Term Name Exists, Append a Unique ID to Slug
- Display all subterms of a custom taxonomy filtered by parent terms
- My list of terms of custom taxonomy displays 7 times
- Display Custom Taxonomy Name As A Shortcode
- Taxonomy template is not reading
- URL issue after setting up Custom Structure in Settings >> Permalinks
- How to assign a default/priority taxonomy to be shown in url in case two taxonomy items are selected
- Post filter with multiple checkbox taxonomy terms
- Combine Categories & Custom Taxonomy
- Custom dropdown search form that allows users to select option B based from Option 1
- issue with saving custom metaboxes fields
- Taxonomy template by post type
- How to loop through 1 CPT with 2 Taxonomies
- Custom terms in custom category taxonomy
- How to setup a taxonomy that can have only one post assigned to it?
- Grouped custom taxonomy query
- Create advanced portal website with sections – taxonomy usage?
- Custom Query for Taxonomy
- Adding a third custom taxonomies
- Why do I get the timeout warning?
- What is the best way to customise admin files so they survive future upgrades?
- Verify nonce in REST API?
- Add custom html to last sub-menu item
- Automatic image renaming based on title
- Manipulating post meta in the customizer
- Php custom query function assistance
- How can I manage my multiple wordpress websites from main website?
- User Roles Not Sticking
- Login form in popup
- Replace “WordPress” word in title of Dashboard
- WordPress custom login page
- How do you modify the WordPress directory structure?
- Change WooCommerce product price based on category and GEO IP country
- Gallery IDS and Captions: hide/show on a per ID basis
- Properly customizing login/register form
- Change the Labels of Users to Customers in Admin
- Choose sidebars column in widgets.php page [closed]
- Unable to sanitize in customizer and escape in theme without removing ability for user to use “< br >” to insert a line break
- Custom column working problem
- WPML Plugin Not displaying multilingual Menus
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- How to remove footer from just homepage
- Create small dashboard widget
- Custom font size nav bar
- Can Username and Password be passed to WP Login page in an IFrame?
- Returning or use form data using a hook?
- Default Display Name As Username
- If custom image header does not exist display text header
- Edit value=”” of a button in child theme
- Taking over my late husbands wordpress blog that we shared
- Creating php pages in wordpress and assigning them to wordpress pages
- Position a hard-coded menu item
- Custom blog setting directs blog to index page
- Trying to set specific image dimensions and crop with ACF
- title tag function
- How to do multi site setup
- Where’s did this div element come from?
- No plugin populate user information in to form
- Best practice to generate token for email action
- how to change the url rediction of the woocommerce login page of the flatsome theme for my own in wordpress?
- Can’t do a src to node modules folder
- Woocommerce – Remove cart button depending product (post) status
- Login CSS style doesn’t load instantly
- Query Posts to display all posts with category “custom field value”
- Trouble getting started in wordpress – my experience isn’t in wordpress.
- Customizer API and pages
- Editing a theme’s templates
- How to delete orphan userdata from array in wp-options
- Custom Style per Post, How to Display Custom-Styled Single post on Homepage?
- Twenty Eleven theme, how to change style to a specific “format”
- Changes to code not displaying
- Permalink Listing WordPress
- Has the table name in SQL for WordPress changed from WP_posts to WPCS_post?