0
我正嘗試使用構建到Wordpress中的「get_term_by」函數根據術語名稱檢索術語ID。但是,這個函數只能從我得到的數組中獲取一個項目。但是這個數組中有多個項目。Get_term_by只返回數組中的一個項目
這是我當前的代碼:
$filter_terms = get_term_by('name', $widget['select'], 'portfolio-categories');
這裏面是什麼$widget['select']
當我傾倒:
array(2) { [0]=> string(5) "Beard" [1]=> string(3) "Tag" }
這陣「大鬍子」和「標籤」,在
所以是兩個方面,其中我想獲得ID,但是,如果我轉儲$filter_terms
我得到這個:
object(WP_Term)#634 (10) {
["term_id"]=> int(14)
["name"]=> string(5) "Beard"
["slug"]=> string(5) "beard"
["term_group"]=> int(0)
["term_taxonomy_id"]=> int(14)
["taxonomy"]=> string(20) "portfolio-categories"
["description"]=> string(0) ""
["parent"]=> int(0)
["count"]=> int(2)
["filter"]=> string(3) "raw"
}
那麼如何從兩個術語中獲得以上信息,除了僅有一個?
編輯: 感謝樂於助人的人,在以上我wordpress.stackexchange.com現在有一個有效的解決方案:
$filter_terms = array();
foreach ($widget['select'] as $key => $name) {
$filter_terms[$key] = get_term_by('name', $name, 'portfolio-categories');
}