我正在使用下面的代碼來顯示當前帖子的類別(不包括 cat id 14)。問題是它們不是我想要的順序。我需要它們按選單順序顯示.. 這可能嗎?
$categories = get_the_category();
foreach($categories as $category) {
$output = $category->cat_name;
if($category->cat_ID !== 14){
echo $output;
}
}
uj5u.com熱心網友回復:
在評論中討論后:
get_the_category()不接受 orderby 子句,因此請wp_get_post_terms()改用。
像這樣使用它
$terms = wp_get_post_terms( get_the_id(), 'category', array( 'orderby' => 'term_order' , 'exclude' => array(14)));
這樣,ID 為 14 的術語也被排除在外。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/355636.html
標籤:php WordPress的
