如何解决如何在 WordPress 中查询标准和视频帖子格式?
我正在尝试根据帖子格式查询帖子。目前,我的网站上有视频、图库和标准帖子格式。单独查询这些帖子格式非常容易。但是,我有 10 个标准帖子和视频帖子格式的税务查询组合,我的查询失败了。
这是我现在拥有的代码:
$args = array(
'post_status' => 'publish','orderby' => 'date','posts_per_page' => 10,'relation' => 'OR','tax_query' => array(
array(
'taxonomy' => 'post_format','field' => 'slug','operator' => 'IN','terms' => array( 'post-format-video' )
),array(
'taxonomy' => 'post_format','field' => 'slug','terms' => array( 'post-format-video','post-format-gallery' ),'operator' => 'NOT IN'
)
)
);
$query = new WP_Query( $args );
解决方法
我认为,您应该将 'relation' => 'OR',
放入 'tax_query'
-Array。
您在错误的位置添加了 'relation' => 'OR'
。它应该在 tax_query
数组内。检查下面的代码。
$args = array(
'post_status' => 'publish','orderby' => 'date','posts_per_page' => 10,'tax_query' => array(
'relation' => 'OR',array(
'taxonomy' => 'post_format','field' => 'slug','operator' => 'IN','terms' => array( 'post-format-video' )
),'field' => 'slug','terms' => array( 'post-format-video','post-format-gallery' ),'operator' => 'NOT IN'
)
)
);
$query = new WP_Query( $args );
有用的链接
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。