admin管理员组文章数量:1318580
Using WP_Query() I want to display all posts -except- those with the 'image' post_format. I tried this, but it did not work.
$args = array(
'relation' => 'NOT',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-' . $post_format),
)
),
'paged' => get_query_var('paged')
);
query_posts( $args );
Using WP_Query() I want to display all posts -except- those with the 'image' post_format. I tried this, but it did not work.
$args = array(
'relation' => 'NOT',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-' . $post_format),
)
),
'paged' => get_query_var('paged')
);
query_posts( $args );
Share
Improve this question
edited Oct 20, 2020 at 18:36
jchwebdev
asked Oct 20, 2020 at 17:35
jchwebdevjchwebdev
7752 gold badges14 silver badges33 bronze badges
1 Answer
Reset to default 1It didn't work because your tax query is missing the operator which should be set to NOT IN
. So just add it like so:
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-' . $post_format ),
'operator' => 'NOT IN',
)
),
And please, avoid using query_posts()
— use new WP_Query()
or get_posts()
instead — or hooks such as pre_get_posts
for modifying the query parameters.
本文标签: wp queryHow to display all posts not in a postformat
版权声明:本文标题:wp query - How to display all posts not in a post_format 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742046489a2417817.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论