簡體   English   中英

WP_Query:如果我結合“p”和“tax_query”,“tax_query”子句將被忽略

[英]WP_Query : if I combine 'p' AND 'tax_query' , 'tax_query' clause is being ignored

如果我執行此查詢:

new WP_Query(array( 
            'post_status' => 'publish',
            'post_type' => 'page', 
            'tax_query' => array(
                        'relation' => 'OR',
                            array(
                                'taxonomy' => 'post_tag',
                                'field' => 'slug',
                                'terms' => 'type1',
                            ),array(
                                'taxonomy' => 'post_tag',
                                'field' => 'slug',
                                'terms' => 'type2',
                            )
                        ) 
            )
        );

它返回一個空數組,它是正確的

但是如果我嘗試使用子句“p”執行相同的查詢,它會返回數據並忽略 tax_query 子句。

new WP_Query(array( 
            'post_status' => 'publish',
            'post_type' => 'page', 
            'p' => 300 ,
            'tax_query' => array(
                        'relation' => 'OR',
                            array(
                                'taxonomy' => 'post_tag',
                                'field' => 'slug',
                                'terms' => 'type1',
                            ),array(
                                'taxonomy' => 'post_tag',
                                'field' => 'slug',
                                'terms' => 'type2',
                            )
                        ) 
            )
        );

看起來您使用了不正確的帖子類型。 您不能將 post_tag 用於頁面帖子類型,因為它僅用於帖子分類。

new WP_Query(array( 
    'post_status' => 'publish',
    'post_type' => 'post', 
    'tax_query' => array(
        'relation' => 'OR',
        array(
            taxonomy' => 'post_tag',
            'field' => 'slug',
            'terms' => 'type1',
        ),
        array(
            'taxonomy' => 'post_tag',
            'field' => 'slug',
            'terms' => 'type2',
        )
    ) 
));

暫無
暫無

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

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