…
$args = array(
\'post_type\' => \'wr_event\',
\'posts_per_page\' => -1,
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => $order,
\'meta_value\' => $yesterday,
\'meta_compare\' => $compare,
if ( is_null($cat) )
\'tax_query\' => array(
array(
\'taxonomy\' => \'event_type\',
\'field\' => \'slug\',
\'terms\' => $cat,
\'operator\' => \'IN\'
),
)
);
我很困惑,我应该通过什么才能从所有条款中获得所有帖子?现在我可以通过
sports
为了获得所有体育赛事,但我如何获得所有赛事?我知道我可以摆脱
tax_query()
然而,我用它作为参数,在这里我可以传递一定的税,如果不是,我想要所有的帖子。
最合适的回答,由SO网友:Rarst 整理而成
简单地省略(或不添加)tax_query
部分参数。
$args = array(
\'post_type\' => \'wr_event\',
\'posts_per_page\' => -1,
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => $order,
\'meta_value\' => $yesterday,
\'meta_compare\' => $compare,
);
if ( ! is_null($cat) )
$args[\'tax_query\'] =array(
array(
\'taxonomy\' => \'event_type\',
\'field\' => \'slug\',
\'terms\' => $cat,
\'operator\' => \'IN\'
),
);