【问题标题】:WooCommerce get parent category from current category pageWooCommerce 从当前类别页面获取父类别
【发布时间】:2017-05-05 18:57:44
【问题描述】:

如何从 WooCommerce 中的子类别页面获取父类别?经过广泛的研究,这段代码看起来很有希望

get_ancestors( $product_cat_id, 'product_cat' );

但它一直在循环中返回“数组”。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:
    $parentcats = get_ancestors($product_cat_id, 'product_cat');
    

    这是正确的方法,您将获得一个或多个父类别,作为一个数组并循环它以获得如下值:

    foreach($parentcats as $parentcat){
        echo $parentcat;
    }
    

    【讨论】:

    • 好东西。我用它来获取当前 id: $cate = get_queried_object(); $cateID = $cate->term_id;它工作得非常好。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    相关资源
    最近更新 更多