在Wordpress上的高级搜索表单中获取Taxonomy-name而不是Taxonomy-slug

时间:2013-07-30 11:50:01

标签: php wordpress forms function custom-taxonomy

我正在编写这个名为“如何为WordPress创建高级搜索表单”(http://fearlessflyer.com/2012/10/how-to-create-an-advanced-search-form-for-wordpress/)的教程,它完美无缺。但是我试图在第一个“选项”选择器中显示Taxonomy-name而不是Taxonomy-slug时遇到问题。

我知道问题出现在'functions.php'中,但我不知道如何重写它以获得我想要的东西:

function buildSelect($tax){  
$terms = get_terms($tax);
$x = '<select name="'. $tax .'">';
$x .= '<option value="">'. ucfirst($tax) .'</option>';
foreach ($terms as $term) {
    $x .= '<option value="' .$term->slug . '">' . $term->name . '</option>';
}
$x .= '<select>';
return $x;
}

我很感激有任何帮助来解决这个问题。非常感谢你。

1 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情:

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); echo  $term->name;