Support » Fixing WordPress » Printing the product's category

  • In the theme I am using I have a loop where $product is accessed and I’d need to figure out if this product belongs to a certain category named “freebie”. How could I do this or at least print all of this product’s category/category ID’s inside a loop?

Viewing 2 replies - 1 through 2 (of 2 total)
  • is_category( 'Stinky Cheeses' );

    where ‘Stinky Cheeses’ is the name of your category.

    if ( is_category( 'Stinky Cheeses' ) ) {
      echo 'this is in stinky cheeses category!';

    or to list all categories inside of a loop:

    $categories = wp_get_post_categories( $post->ID );

    Thank you but seems that doesn’t work in this case because I am trying to do this inside a loop in a file content_product.php

    If I could somehow get the ID of the product in loop, I believe it would work then. Now I am getting an empty array if I try to do that second option with $post->ID. $product don’t seem to have a value $product->ID accesible. Any hints? 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Printing the product's category’ is closed to new replies.