Cannot output Category
-
I would like to display selected woocommerce categories in a custom wp page template; ie: template-getshorty.php. The problem I’m having is
everythings loads just fine but I can’t seem to add a condition where I get the output of categories which i want.
Wrapping the code with the Woocommerce conditionals doesn’t seem to have any effect on the code because from what I’m understanding is the
Woo Conditionals have Conditionals also ?? : ie (is_product_category() is to be used on woocommerce category archive pages only. This
conditional tag will return always false in all other pages (shop pages, product single pages, cart, checkout, my-account pages…).Can anyone tell me how to get this code to out only the categories I would like ie: (is_product_category(‘fish’,’cat’ ,’dog’etc).
The typical conditionals would’ve been awesome had it
worked but it seems like a no go.
Thanks in advance ??CODE:
$args = array( 'number' => $number, 'orderby' => 'parent', 'order' => 'ASC', 'hide_empty' => $hide_empty, 'include' => $ids ); $product_categories = get_terms( 'product_cat', $args ); $count = count($product_categories); if ( $count > 0 ){ foreach ( $product_categories as $product_category ) { echo '<p><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></p>'; $args = array( 'posts_per_page' => -1, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_cat', 'field' => 'slug', // 'terms' => 'white-wines' 'terms' => $product_category->slug ) ), 'post_type' => 'product', 'orderby' => 'title,' ); $products = new WP_Query( $args ); } }
- The topic ‘Cannot output Category’ is closed to new replies.