Title: Cannot output Category
Last modified: September 4, 2018

---

# Cannot output Category

 *  Resolved [Dono12](https://wordpress.org/support/users/dono12/)
 * (@dono12)
 * [7 years, 9 months ago](https://wordpress.org/support/topic/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 );
           }
       }
       ```
   
    -  This topic was modified 7 years, 9 months ago by [Dono12](https://wordpress.org/support/users/dono12/).
    -  This topic was modified 7 years, 9 months ago by [Dono12](https://wordpress.org/support/users/dono12/).
    -  This topic was modified 7 years, 9 months ago by [Dono12](https://wordpress.org/support/users/dono12/).

Viewing 1 replies (of 1 total)

 *  Plugin Support [John Coy a11n](https://wordpress.org/support/users/johndcoy/)
 * (@johndcoy)
 * Automattic Happiness Engineer
 * [7 years, 9 months ago](https://wordpress.org/support/topic/cannot-output-category/#post-10674666)
 * Hi [@dono12](https://wordpress.org/support/users/dono12/)
 * WooCommerce has shortcodes to help you achieve showing products of a specific
   category, as shown on this documentation page:
 * [https://docs.woocommerce.com/document/woocommerce-shortcodes/#product-category-shortcodes](https://docs.woocommerce.com/document/woocommerce-shortcodes/#product-category-shortcodes)
 * Hope that helps.

Viewing 1 replies (of 1 total)

The topic ‘Cannot output Category’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [John Coy a11n](https://wordpress.org/support/users/johndcoy/)
 * Last activity: [7 years, 9 months ago](https://wordpress.org/support/topic/cannot-output-category/#post-10674666)
 * Status: resolved