快速测试一下,两种方法似乎都很有效。
// @Rup\'s method
$terms = get_the_terms(get_the_ID(), \'my_taxonomy\');
if (!is_wp_error($terms) && !empty($terms)) {
foreach ($terms as $term) {
// skip if parent > 0
if( $term->parent )
continue;
$name = $term->name;
$link = add_query_arg(\'fwp_typ\', FWP()->helper->safe_value($term->slug), \'https://www.freuciv.com/\');
echo "<a href=\'$link\'>$name</a><br />";
}
}
或
$terms = get_the_terms(get_the_ID(), \'my_taxonomy\');
if (!is_wp_error($terms) && !empty($terms)) {
foreach ($terms as $term) {
// only do if parent is 0 (top most)
if( $term->parent == 0 ) {
$name = $term->name;
$link = add_query_arg(\'fwp_typ\', FWP()->helper->safe_value($term->slug), \'https://www.freuciv.com/\');
echo "<a href=\'$link\'>$name</a><br />";
}
}
}