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
- How to detect single.php (but not single-portfolio.php)?
- Different post sort order within different categories
- 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
- Related Posts by Multiple Tags?
- HTML code in Custom field
- How to have different content in the loop and single
- Single.php Active Category Class
- custom single.php not working
- 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
- disable column on post and user list
- Get taxonomy terms only of the WP_Query current posts
- How to disable single post view in wp
- Custom Post Templates
- How to check the terms in single custom post type template
- Can’t get the_content of the parent page from its single post?
- Get posts by name and taxonomy term
- How to show single post page as home page
- 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
- How to bulk-untag multiple posts?
- Force the “Choose from the most used tags” meta box section to always be expanded
- Get Posts Under Custom Taxonomy
- Add Read More Tag to a post content (Single.php)
- If in_category not working for multiple single.php pages
- How can I setup a relationship using categories in WordPress?
- 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
- 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
- Multiple comment forms on a single page
- Is there a query string for edit.php to show all posts that have no custom taxonomy terms?
- Single Post in Tab/Slider
- Defined function isn’t showed on page
- wp_set_object_terms NOT working on CPT, but wp_set_post_terms does
- Only allow posts with a specific term to only be viewed by other authors with the same term in their post
- Count the number of a post types associated with another post type
- Get current post’s nav menu name (term name)
- Changing wp_link_pages() to “Next Page” and “Previous Page” buttons?
- Attachment image single page
- Nest Next and Previous in a href with class that has a background image
- Making a wordpress page print friendly
- WordPress single.php different layouts projects / posts
- Geting error in post and category [closed]
- “Home” Page now only displaying the single latest post
- How to associate a custom taxonomy to a post multiple times
- How to display the post categories for each post inside the loop with custom format?
- WP posts using index.php instead of single.php
- Create/Set Category as Title of Post
- Taxonomy checkboxes not showing current status on edit page
- Single post shows post three times
- How do I check if a post is password protected?
- Loop through taxonomies and loop through their terms (Newbie question)
- Slug collision between page, taxonomy and custom post type
- wordpress display posts by terms id or name
- Pagination for single post
- Filter By Term Not Working – Custom Post Type
- Get the category of post
- Custom Taxonomy From Database
- List posts of assigned categories in list of all categories on single.php
- Is possible to do this from function.php
- Custom Single Post Type not referring to single-post-type.php File
- Thumbnail With Next/Prev Links Not Showing Next Post?
- How can add posts without category into category
- 404 for some custom taxonomy not ALL taxonomy
- Pagination and Related Posts
- Loop through posts by each term and exclude duplicate posts assigned to several terms
- Multiple loops on a Search result page?
- Single post page from static home not working
- Get current post’s child page?
- 1 post, 2 templates
- retrieve post slug by post_tags taxonomy
- Taxonomy Category category.php not working
- Insert Shortcode exactly at the end of the content
- WordPress More tag doesn’t work on Single post
- How to make ‘show_option_all’, that comes from wp_list_categoreis, to work with get_categories or with get_terms?