To list all categories including categories with no products in wordpress

  • 0

Add

hide_empty = >0 as parameter

Eg:-

<?php
$args = array(
‘post_type’ => ‘product’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’,’hide_empty’=> 0);
$product_categories = get_terms(‘product_cat’, $args );
foreach ( $product_categories as $product_category ) {
echo $product_category->name . “<br />”;

}
?>

Add hide_empty = >0 as parameter Eg:- <?php $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’,’hide_empty’=> 0); $product_categories = get_terms(‘product_cat’, $args ); foreach ( $product_categories as $product_category ) { echo $product_category->name . “<br />”; } ?>

Add hide_empty = >0 as parameter Eg:- <?php $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’,’hide_empty’=> 0); $product_categories = get_terms(‘product_cat’, $args ); foreach ( $product_categories as $product_category ) { echo $product_category->name . “<br />”; } ?>