【发布时间】:2020-12-03 10:59:36
【问题描述】:
如果我执行这个查询:
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',
)
)
)
);
【问题讨论】:
-
我认为您必须将
'p' => 300 ,更改为'page_id' => 300,p参数用于帖子ID,并且您正在查询页面 -
如果我只使用“p”(或“page_id”)查询工作正常。另外,如果我只使用 tax_query