我有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