簡體   English   中英

數組無法正常工作於get_terms函數

[英]Array not working as intended in get_terms function

我正在調用WordPress的get_terms函數,但我想排除多個類別。

為什么這無效?

$terms = get_terms( 'category', 'exclude' = array(1, 238) );

我發現我必須使用此:

$terms = get_terms( 'category', array('exclude' => array(1, 238),) );

但是這似乎是多余的,因為高階數組中只有一項。

供參考的文檔: https : //developer.wordpress.org/reference/functions/get_terms/

您可以使用:

$taxonomy  = 'review-product';

$post_type = 'reviews';

$args = [

    'post_type' => $post_type,

    'tax_query' => [
        [
            'taxonomy' => $taxonomy,
            'terms'    => get_terms( $taxonomy, [ 'fields' => 'ids'  ] ),
            'operator' => 'NOT IN'
        ]
    ]
];

$query = new \WP_Query( $args );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM