Check the parent of each category, top-level terms will have a parent value of 0:
$product_category = wp_get_post_terms( $post->ID, 'product_cat' );
foreach( $product_category as $cat ):
if( 0 == $cat->parent )
echo $cat->name;
endforeach;
Related Posts:
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Upgrade 4.5.2 to 4.5.3 deleting row in wp_options table
- Between functions.php (theme), widgets, and plugins, which is loaded first?
- How do you debug plugins?
- How can I make default jquery version of WordPress “async”?
- How to add plugins to wordpress theme?
- Importing Tweets with certain hashtags into WordPress
- Get php var inside javascript file (making plugin)
- Find out what is using PHP sessions in WordPress
- Using Vagrant for customizable WordPress Multi-sites [closed]
- How to update WordPress plugin readme.txt description page without triggering a plugin update?
- publish_post hook isn’t working for scheduled posts
- Creating a theme option page?
- Pages with 2 Columns
- Add post thumbnail from external image with plugin
- Is it possible to add an action to the currently running action?
- Google Maps and Yandex Maps doesn’t work correctly
- How do I get slug of all active plugins programmatically?
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- unzip a folder on specific location and delete the zip file
- Check if User exists in WordPress Multisite
- WooCommerce – results per page not working after page reload
- WordPress author details plugin/widget
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- Plugin version is not showing up in wordpress.org plugin directory
- Saving changes in wp_editor
- Removing customise fields during plugin uninstallation
- plugin class inheritance. cannot change variable
- Modifying the comments section through a plugin regardless of theme
- How to get specific setting by settings_fields()?
- Search for categories
- Best way to initiate a class in a WP plugin?
- Why this function not working for install database on plugin activation
- The Hook registration_errors was not called
- What happens if I don’t update my plugins?
- Hide certain widgets from specific user roles in admin
- Delay JavaScript files from loading
- Front-end CSS Library for plugin [closed]
- Add bcc to contact from on wordpress
- Default taxonomy template in plugin, override in theme
- WordPress Plugins Don’t Automatically Update
- Simply poll & Events Calendar plugins clashing
- WordPress plugin Post Creation [closed]
- How I can change the required capability for an admin menu without editing the plugin file?
- How to add support for caching plugins for my own plugin?
- wp_enqueue_scripts
- woocommerce search by sku and title ajax
- WordPress Site is Broken, Cannot see wp-admin page [closed]
- How to remove a CPT Menu from the Root Admin only
- Get post_id on clicking a link in WordPress
- WordPress.org: How to add a plugin for certain countries?
- Wp Debug Enabled True Notices and Warning
- Webservice credential storage [duplicate]
- Development workflow for WordPress using git – issues with plugins and bloginfo(‘wpurl’)
- Fancybox plugin: triggering on href attribute
- Is there a Image Gallery which will load all my posted Images like twitter’s image grid?
- Gravatar alternative for WordPress
- Constructing a Pay to Download music website with wordpress
- Installing a Plugin ( Which is already manually uploaded )
- How to use wordpress plugin functions on my “home” page?
- Uninstalling IntenseDebate
- how i could put my id in the meta field ‘meta-value’
- WooComerce Deposit: set specific shipping method and quantity based deposit amount
- Menu not closing after clicking – WordPress – Elementor
- Translations not appended even strings are edited
- Is there any way to sync Facebook Comments and with comments on WordPress website?
- Is there a way to auto generate poster image for videos
- wp_create_user not working on plugin file
- Different Google Analytics code based on Users Device
- On wp-admin menu, the slider revolution option leads to a 404 error, page not found
- Reverse count page view and show on other page
- Block content rendering on the top just below body tag
- Will downloading a page builder plugin delete my existing data?
- How to submit custom form data using ajax to HubSpot form?
- Unable to import complete data remote wp-cli wordpress
- Register setting on plugin activation
- Add a filter to a method in the parent theme
- WordPress not displaying information on post sent from custom admin form
- How can I automatically send an email with an excel file containing submissions for a form rather than an email per submission?
- Run only on plug-in activation instead of wp_head
- How can I easily add code under the tag without using hooks? [duplicate]
- Problem with Duplicate Meta / tag description in Webmaster Tool [duplicate]
- Add “selected” class to custom taxonomy dropdown search
- page creator to leave comments ONLY
- Differentiate attachment pages in search results
- How to get the parameters on page and avoid 404?
- Working on fixing wp-front-end-editor, encountering undefined index
- How to add plugin activity in the menus?
- Photos do not show on SEO platform built into a wordpress plugin
- Share Button Like SuperUser
- Couldn’t find a documentation for a filter API in plugin development
- phpBB 3 to bbPress
- What plugin(s) are best for this User registration task? [closed]
- Trying to display posts but getting the pages as output
- How to show random feed from DB and show content in my site
- Plugins not showing on dashboard?
- register_activation_hook not working
- Stop the user if login from the cookies
- Change weird Wp File structure
- LiteSpeed cache image Optimization