Wordpress: Query Posts without allocated taxonomies

给你一囗甜甜゛ 提交于 2019-12-09 13:11:31

问题


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'
    ),
);

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?

EDIT: Another solution would be to query all terms, an exclude it then in tax_query. But I would like to save this query.


回答1:


query_posts( array( 'post_type' => 'discography', 'new taxanomy name' => 'created taxonomy' ) );

This guide for custom post type and custom taxonomy.



来源:https://stackoverflow.com/questions/7928368/wordpress-query-posts-without-allocated-taxonomies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!