Wordpress help with select posts with query_post

2019-08-29 07:50发布

I am currently doing the following to select posts from a custom post-type,

query_posts('post_type=slideshow')

I need to somehow make sure that only posts are return if the the taxonomy "available" is returned as NULL or alternatively != to "mobile" is this possible?

So far I have tried,

query_posts('post_type=slideshow&not_in_category=14')

and also

query_posts('post_type=slideshow&available=null')

but to no avail. What else can I try?

标签: php wordpress
2条回答
仙女界的扛把子
3楼-- · 2019-08-29 08:17

Try this...

$post_type = "slideshow";
//your custom taxonomy name... 
$taxonomy = "available";
//put the term_id for the term "mobile" you want to exclude in an array
$excluded_term_ids = array(1234);

$args = array(
    "tax_query"=>array(
        array("taxonomy"=>$taxonomy, 
              "terms"=>$excluded_term_ids,
               "field"=>"term_id",
               "operator"=>"NOT IN"
        )

    ),
    "post_type"=>$post_type
);
$query = new WP_Query();
$posts = $query->query($args);
var_dump($posts);

I'm doing a similar thing right now with "advanced search" over multiple custom taxonomies, and this seems to work. You might also take a look at the WP code in wp-includes/query.php and wp-includes/taxonomy.php.

查看更多
登录 后发表回答