To display only assigned category you need to change hide_empty to true.
Please see the modified code:
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => true,
'parent' => 134,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
echo '<ul class="wooc_sclist">';
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );
echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
}
echo '</ul>';
Please see the updated code:
$cats_list = get_the_terms ( get_the_ID() , 'product_cat' );
echo '<ul class="wooc_sclist">';
foreach ($cats_list as $cats) {
$link = get_term_link( $cats->slug, $cats->taxonomy );
echo '<li><a href="'. $link .'">'.$cats->name.'</a></li>';
}
echo '</ul>';
Related Posts:
- WordPress Ajax always returns a 404 error
- Calling a method from functions.php on a click of a button
- Nice scroll to wordpress
- Javascript code inside “” in core WordPress files .php
- Minify HTML, CSS, JS with PHPWee?
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- Slide in Panel WordPress Post
- Show post in slider
- Populate dropdown with Child Pages based on Parent Page chosen
- search and replace preword from author
- WP grandchild categories in nested ul li
- How to change redirection route to a php page for making it only accessible by logged-in members?
- selected option if current category is the value
- parts of url disappear when using # inside href=”” [closed]
- Different post styles depending on category
- Noscript not working as it should in wordpress site
- get taxonomy thumbnail and use it as a variable in code
- Add Codepen animation as Preloader to WordPress
- HTML escaping data with ajax requests
- Override user-edit.php to design own profile page
- How to change logo by category
- Calling PHP Titles inside Javascript Markup
- Link to page with posts of specific type
- Replacing WordPress Icons (menu,icons32, etc)?
- go to home page when i select default in select-box
- Is it possible to isolate and use WordPress functions outside of wordpress
- Time Delay a URL Redirect for Specific Page
- Cascading dropdown select search based on Parent Page & Child Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Display WordPress search results based on the selected Sub-Category
- html form: redirect page after form completes submit function and posts data
- WordPress User Meta value variable into Google Gauge Chart
- List sub categories and corresponding posts of a parent category
- Search bar for wp menu
- Adding HTML Code to Replace Text in PHP
- Executing php on button press
- Add other class content with reference class value
- Using Google Analytics in an enqueued JS file
- separate list of programs in html/javascript coming from php
- How to enable HTML tags in category description without breaking the category page
- How to use wp_ajax_set_post_thumbnail?
- Passing a value from an input field to a php function in WordPress?
- How do I disable cache for a certain page?
- WordPress Slider is not working
- How can i show specific Category List?
- sessionStorage saves input value in browser but it is not loaded in the form field
- Collapsible menu on post sidebar only expands and does not collapse
- Target a specific container to style on WordPress storefront theme
- scroll scrpit to particular button position to next id when click button
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Code works on page-example.php by not category-example.php
- Where to find the html for WordPress site? [closed]
- I need help implement a Javascript code into the PHP file
- Trying to customize wordpress drop down categories
- Is there a better way to output HTML as a shortcode?
- Load wp_editor on button click
- Slick slider not working on wordpress
- Create Image Uploader for Widget
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Customizer Show/Hide Logo and Site Title
- Use different javascript files for each page on website
- Categories Template Assistance
- Click loads template via ajax
- Sending jsPDF documents to the server
- How to get the POST TITLE using the POST ID?
- js file in root loading without
- Use menu link or onClick to set a variable
- Load a page into a div with Ajax
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- Applying A Category to Existing Posts Where Page Title Matches Regex
- wordpress visual composer change grid builder post link
- Let Users Choose Post Categories
- PHP array to JS array to use in google map
- Fancybox type popup window that’s not an iframe
- how to make my website secured
- How to correctly add Javascript to this PHP ‘Page Not Found’ Page?
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- element not working in Safari [closed]
- How to Change CSS Colors from Custom Plugin Settings Page
- Passing the name of selected color from the custom component to `render_callback`
- Echoing a CSS class based on category of post in a list
- How to use the checked() function to check for a non-empty var
- How can I get my Media Uploader Button to function on 1 click rather than requiring 2 clicks?
- Compare current post Category in select menu
- how to changes mobile menu toggle breakpoint in WordPress
- How to store checkbox data for individual users?
- PHP inside echo HTML
- How to show categories and date on posts
- using shortcodes inside gravity forms
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- Allow two posts (from different categories) to have the same slug
- Creating a POP Alert
- Can’t display anything through homepage text editor
- WooCommerce multiple custom fields code
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- Pass form attributes to another php template in wordpress
- How to create a radio button to alt between settings in wp_options table
- How to list categories by page id in wordpress
- Showing the project type in HREF
- WooCommerce – Print Processing orders [closed]