我有3种类型的职位如下WordPress的 - 显示所有帖子+那些与特定的标签
- 普通的帖子没有任何标签
- 以“特色”标签
- 随着“售出”标签
在一个页面上,我只想显示普通帖子+带精选标签的帖子,并且不想显示带有“已售出”标签的帖子。我怎样才能做这个查询?
感谢
我有3种类型的职位如下WordPress的 - 显示所有帖子+那些与特定的标签
在一个页面上,我只想显示普通帖子+带精选标签的帖子,并且不想显示带有“已售出”标签的帖子。我怎样才能做这个查询?
感谢
您可以使用get_posts
功能与tax_query
参数。
因为它很简单,我不认为我应该进一步写东西,只是读 下一部分从食品:
http://codex.wordpress.org/Template_Tags/get_posts#Taxonomy_Parameters
您最好使用WP_Query
,做这样的事情:
// you'll need the term_id of the tags you would like to exclude
$sold_tag = get_term_by('name','sold','post_tag');
$featured_tag = get_term_by('name','featured','post_tag');
// create a query object, this will pick all posts except the ones tagged with 'sold'
// if you wanted to pick all post marked as sold or featured and everyone not marked
// as for instance 'fruit' + all that isn't tagged at all you could use a combination of
// tag__not_in => array($fruit->term_id) && tag => array('featured,sold')
//
$query = new WP_Query(
array('post_type' => 'post',
'tag__not_in' => array(
$sold_tag->term_id
)
)
);
// start the loop
while($query->have_posts()): $query->the_post();
// output post here ...
endwhile;
了解更多关于WP_Query
你解决你的PROBL他们吗? – Cyclonecode