嗨,如何从特定术语中获得子项并排除某些特定条款

发布于 2025-02-08 16:14:51 字数 398 浏览 1 评论 0原文

我正在努力添加“排除”,以排除以下代码的某些条款。 我找不到编写这样的数组的正确方法。谁能帮我吗?谢谢

<?php
$terms = get_terms( 'product_cat', 'parent=175' );
$count = count($terms);
if ( $count > 0 ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li><a href="'. get_term_link( $term ) .'">'. $term->name . '</a></li>';
    }
    echo '</ul>';
}
?>

I am struggling to add 'exclude' to exclude some terms for the below code.
I cannot find the correct way to write such an array. Can anyone help me? Thanks

<?php
$terms = get_terms( 'product_cat', 'parent=175' );
$count = count($terms);
if ( $count > 0 ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li><a href="'. get_term_link( $term ) .'">'. $term->name . '</a></li>';
    }
    echo '</ul>';
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

憧憬巴黎街头的黎明 2025-02-15 16:14:51

您对get_terms的使用不正确。
它需要一系列这样的论点:


$terms = get_terms( array( 
 'taxonomy' => 'product_cat',
 'parent'   =>  $parent_id,
 'exclude'  =>  array( $ids, $to, $exclude )
 ) );

your usage of get_terms is incorrect.
it takes an array of arguments like so:


$terms = get_terms( array( 
 'taxonomy' => 'product_cat',
 'parent'   =>  $parent_id,
 'exclude'  =>  array( $ids, $to, $exclude )
 ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文