wordpress get_the_category returns empty

后端 未结 1 1449
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 20:08

After a new comment is saved, I’m able to redirect via functions.php

add_filter(\'comment_post\', \'myredirect\');

I want to redirect to the product

1条回答
  •  一整个雨季
    2021-01-21 20:15

    I got it solved via get_the_terms using this snippet from WooCommerce - get category for product page

    $terms = get_the_terms( $post_id, 'product_cat' );
    foreach ($terms as $term) {
        $product_cat_id = $term->slug;
        break;
    }
    

    Foundit when i looked for product instead of post. :-)

    0 讨论(0)
提交回复
热议问题