我还没有对此进行测试,因此可能需要对其进行调整(特别是,我不确定我是否在术语对象上正确地找到了参数的名称),但这应该可以让您大致实现这一点。
//add filter
add_filter( \'get_the_terms\', \'my_exclude_terms\', 10, 1 );
//function to do filtering
function my_exclude_terms( $terms ) {
//only filter for the homepage
if( is_home() ) { // you may want to use is_front_page(), depending on your settings
//list the unwanted terms
$unwanted_terms = array( // fill this array with the unwanted term ids, slugs, or names
14,
18
);
// loop through the terms
foreach( $terms as $k => $term ) {
//only remove term if it\'s ID or slug is in the array.
if(
in_array( $term->term_id, $unwanted_terms, true ) || //comment out this line to remove term ID checking
in_array( $term->slug, $unwanted_terms, true ) || //comment out this line to remove slug checking
in_array( $term->name, $unwanted_terms, true ) //comment out this line to remove name checking
) {
unset( $terms[$k] );
}
}
}
return $terms;
}
我用了
get_the_terms
筛选,因为它是术语转换为HTML之前的最后一个筛选,这使得解析变得非常困难。如果您是PHP的新手,需要帮助进行故障排除或实现,请发表评论。祝你好运