get_terms relates to getting all the terms of a taxonomy. get_the_terms grabs all the terms related to the post.
The problem is that it sounds like you only want to return those terms which are parent categories, not the children, and get_the_terms does not pass an arguments array.
$terms = get_the_terms( get_the_ID(), 'product_cat' );
foreach ( $terms as $term ){
if ( $term->parent == 0 ) {
echo '<div class="parent '.$term->slug.'">' . $term->name . '</div>';
}
}
Related Posts:
- Exclude posts that only have the ‘Uncategorized’ category [duplicate]
- How are terms connected with posts in database?
- Importing data from spreadsheet into wordpress DB, along with custom taxonomies and their terms
- deleting terms programmatically
- Adding Multiple Values to a Post Meta Key
- Avoid duplicate post from same Taxonomy
- Set terms in a custom post
- Get posts of ONE taxonomy term of custom post type
- Setting posts_per_page for taxonomy term template
- How to display posts via custom taxonomy terms using checkboxes?
- Loop parent terms {display posts} AND loop child terms {display posts}
- Displaying Results From Custom Taxonomy Query
- How to get all the terms of a post
- Get Posts Under Custom Taxonomy
- How to detect single.php (but not single-portfolio.php)?
- Different post sort order within different categories
- Custom Single Post By Category
- Displaying the category name of a custom post type
- Passing a hardcoded page/post ID into `get_post`
- MySQL Query to Retrieve Category from wp_posts
- Elegant way to include only published posts with get_objects_in_term()?
- Using single.php from plugin folder instead of default template folder
- Custom permalink structure only for default posts
- Related Posts by Multiple Tags?
- Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy
- How do I create a link that will always show the latest post?
- Convert IPTC keywords to blog post tags
- Post X of Y in single.php / sidebar.php
- HTML code in Custom field
- Show Custom Taxonomy Categories, Listing of Posts, and Single Post via AJAX
- How to have different content in the loop and single
- Single.php Active Category Class
- How to add shortcode tags in single.php [closed]
- custom single.php not working
- How do I get the slug of a custom taxonomy category of a post?
- How to display different single post template based on author?
- Post taxonomy from exif data
- Redirection to taxonomy posts list after post submit.
- Remove custom posts that match taxonomy value
- Using Custom Posts with Metaboxes and Drop-downs
- Does an action fire when adding a tag via the “Tags” meta box?
- how load content as pop-up using ajax
- How can I add a meta-box to the posts editor containing all items of a custom taxonomy as checkbox?
- Disable single post page
- how to know if the post has pagination () or not
- Remove arrows from previous and next link
- disable column on post and user list
- “next_posts_link” and “previous_posts_link” display me NOTHING
- Get taxonomy terms only of the WP_Query current posts
- How to disable single post view in wp
- Custom Post Templates
- Add code just after Post content
- Pagination on single post page?
- How to check the terms in single custom post type template
- Restrict post navigation to current sub menu
- Can’t get the_content of the parent page from its single post?
- Show all posts in sidebar in single.php
- Automatically Updating Publish Date Bug
- Get posts by name and taxonomy term
- How to display data in archive page?
- How to show single post page as home page
- Using wp_list_categories like the the_category (showing just current categories of a post)
- Pass data between pages
- How can I make a post that belongs to a category or have specific tags, display different from the other single posts?
- Display all posts that were published before full post on single.php
- Choose whether to automatically add a taxonomy with the same name as the post
- Display tag image in post using Taxonomy Images plugin index.php
- wp_get_object_terms returns only Uncategorized on first publish
- How to bulk-untag multiple posts?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Posts list in custom taxonomy
- How to Restrict Previous & Next Post Link to Posts of Same Category?
- Get Posts Under Custom Taxonomy
- Prepending %category% onto default posts fails
- get_adjacent_post by language
- Add Read More Tag to a post content (Single.php)
- Duplicate Custom Post Type and Taxonomy Slug
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- If in_category not working for multiple single.php pages
- How can I setup a relationship using categories in WordPress?
- sql select for post_title and a term name
- How can I hide tags on a child-category page, if that tag has not been used?
- 404 error on default post type and default taxonomy fronted page
- Single.php – Get Current Parent Category
- Insert sometext after first h3 in content
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Thumbnail Image to go in the post aswell
- outputting posts’ taxonomies: cant get ‘get_the_taxonomies’ working
- Add get_the_tags() to Single Posts section via functions.php
- Is it possible to customize the post according to post format in single.php?
- Copy taxonomy terms from one post to another programmatically
- Multiple comment forms on a single page
- Post type no single page
- relating business and products with custom taxonomy?
- Is there a query string for edit.php to show all posts that have no custom taxonomy terms?
- Single Post in Tab/Slider
- WordPress bulk category select when publishing post
- Check if current user has a post and that post has any term/s from a specific custom taxonomy outside the loop
- Parent category / child category posts
- Defined function isn’t showed on page