WordPress的:查询没有分配分类法的帖子 [英] Wordpress: Query Posts without allocated taxonomies
问题描述
我想按自定义分类法(由url指定)的特定术语过滤所有帖子查询。目前,我正在使用add_filter('request',...)和'tax_query',它们现在可以使用。
I would like to filter all post queries by a specific term of a custom taxonomy (specified by an url). Currently I'm using add_filter('request', ...) and 'tax_query', which kind of works now.
所以我得到了这个词的所有帖子,但是我想得到这些职位,而这些职位没有为该分类法分配任何术语。
So I get all posts of this term, but I would like to get those posts, which do not have ANY terms allocated of this taxonomy.
我正在尝试类似的操作:
I was trying something like:
$request['tax_query'] = array(
'relation' => 'OR',
array(
'taxonomy' => 'brand',
'field' => 'slug',
'terms' => array( $term )
),
array(
'taxonomy' => 'brand',
'field' => 'slug',
'terms' => NULL,
'operator' => 'IS'
),
);
但是,由于Wordpress不支持 IS或 IS NULL,因此不起作用
But, since Wordpress doesn't support 'IS' or 'IS NULL' this doesn't work either.
那么,有什么主意如何查询一个词的帖子和根本没有一个词的帖子?
So, any idea how to query for posts of a term AND posts without a term at all?
编辑:另一种解决方案是查询所有术语,然后在tax_query中排除它。但我想保存此查询。
Another solution would be to query all terms, an exclude it then in tax_query. But I would like to save this query.
推荐答案
query_posts( array( 'post_type' => 'discography', 'new taxanomy name' => 'created taxonomy' ) );
有关自定义帖子类型和自定义分类的指南。
This guide for custom post type and custom taxonomy.
这篇关于WordPress的:查询没有分配分类法的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!