2
開始。如果我使用WP_Query類例如帖子:獲得有類別名稱的用語
$query = new WP_Query('category_name=staff,news');
我會得到有這些類別的職位,採用類別蛞蝓,但我怎樣纔能有帖子一個類別名稱以一個術語開頭,例如:
$query = new WP_Query('category_name=s%');
我希望我解釋一下我的問題。感謝
開始。如果我使用WP_Query類例如帖子:獲得有類別名稱的用語
$query = new WP_Query('category_name=staff,news');
我會得到有這些類別的職位,採用類別蛞蝓,但我怎樣纔能有帖子一個類別名稱以一個術語開頭,例如:
$query = new WP_Query('category_name=s%');
我希望我解釋一下我的問題。感謝
您可以在主題的functions.php創建一個功能,如:
<?php
/**
* @ $taxonomy = the taxonomy name
* @ $search = the string you are searching
* @ return array of term names
*/
function getDesiredTerms($taxonomy, $search) {
$result = get_terms(
$taxonomy,
array(
'hide_empty' => false, // get them all
'fields' => 'names', // get only the term names
'name__like' => $search // Note: This was changed in WordPress 3.7, when previously name__like matched terms that begin with the string.
)
);
return $result;
}
要知道你所使用的WordPress版本的。
在食典委的更多詳細信息在http://codex.wordpress.org/Function_Reference/get_terms。 尋找'name__like'參數