0

I'm triying to get the category name by the category slug. To be more precise: I'm creating a new shortcode where I ask for the category slug and add that to the query args.. On top of the result I want to display the category name.

For testing I replace the variable with a known slug.

This example returns a NULL

$catObj = get_category_by_slug('salads-entrees'); 
var_dump($catObj->name);

1 Answers1

0

The issue was that a product category is just a taxonomy of the CPT Products. So I was using the wrong function.

$catObj = get_term_by('slug', 'salads-entrees', 'product_cat');
echo $catObj->name;

With get_term_by() I was able to solve my requirement.