开发者

Wordpress help with select posts with query_post

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 alternativel开发者_运维技巧y != 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?


Perhaps this will help? http://wordpress.org/support/topic/query-posts-by-taxonomy


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜