Printing the product's category (3 posts)

  1. liquid8
    Posted 2 years ago #

    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?

  2. Evan Herman
    Posted 2 years ago #

    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 );
  3. liquid8
    Posted 2 years ago #

    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? :)

Topic Closed

This topic has been closed to new replies.

About this Topic