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
- Is It Possible to Block Redirect Checker Tools from Knowing Where URLs are Redirected?
- WordPress Wysiwyg Content not being displayed
- JavaScript, best way to use data from the loop
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Edit category output
- Create custom blocks for bootstrap
- Error: array_map(): Argument #2
- Problems with function on function.php
- HTML table from shortcode with multiple parameters
- Use template for posts with a particular category grandparent
- Run a Parallel PHP Application with WordPress
- Click loads template via ajax
- Put a link to a category round a hard coded A HREF
- Archive dropdown styling not applied
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- How to display a value from a radio button in the options menu in wordpress
- Display notification only once
- Header has extra HTML block at top before my code
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Check if Product is in a Specific Category in Functions.php
- Get/Set wp.customize.previewer.previewUrl
- Custom Loop through category menu to include sub categories
- javaScript in section of WP API
- To echo or not to echo?
- Blank space at beginning of tag?
- Different background-image by category
- How do I add HTML to a PHP function [closed]
- admin-ajax.php responding with 0
- Using wp_localize_script to store the template url into a variable to use in JS
- Custom image upload
- How to display recent posts on home page with custom HTML
- How can the plugin directory path be returned into ?
- Get posts with at least one category in common with current post?
- How to exclude specific category from the get_the_category(); array
- WordPress automatically adds tags when pasting code, how to stop it?
- How can I add tinymce editor in WordPress with jQuery?
- How to speed up admin-ajax.php in wordpress
- JQuery not working on WordPress Admin page [closed]
- Customizer Show/Hide
- Page Reloads Before AJAX Request Finishes