我创建了两个下拉列表,每个下拉列表一个category & tag
并成功筛选帖子。
之后,我创建了一个自定义分类法cat
并尝试在所有三个下拉列表之间过滤帖子。但用于分类的下拉列表cat
不工作。
<form action="<?php bloginfo(\'url\'); ?>" method="get">
<?php
// I use custom taxonomy "Cat"
if( $terms = get_terms( \'cat\', \'orderby=name\' ) ) :
echo \'<select name="cat_name"> <option value="">Cat</option>\';
foreach ( $terms as $term ) :
echo \'<option value="\' . $term->name . \'">\' . $term->name . \'</option>\';
endforeach;
echo \'</select>\';
endif;
// I use default "Categories"
if( $terms = get_terms( \'category\', \'orderby=name\' ) ) :
echo \'<select name="category_name"> <option value="">Categories</option>\';
foreach ( $terms as $term ) :
echo \'<option value="\' . $term->name . \'">\' . $term->name . \'</option>\';
endforeach;
echo \'</select>\';
endif;
// I use default "Tag"
if( $terms = get_terms( \'post_tag\', \'orderby=name\' ) ) :
echo \'<select name="tag"><option value="">Tags</option>\';
foreach ( $terms as $term ) :
echo \'<option value="\' . $term->name . \'">\' . $term->name . \'</option>\';
endforeach;
echo \'</select>\';
endif;
?>
<input type="submit" name="submit" value="filter" />
</form>
它不适用于分类学
cat
&;但是为另外两个工作
category & tag
What I missing or any suggestions to make all three dropdown working?
Optional: 这就是我创建自定义分类法的方式
cat
function custom_taxonomies() {
$labels = array(
\'name\' => \'Cat\',
\'singular_name\' => \'Cat\',
\'menu_name\' => \'Cat\'
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'cat\' )
);
register_taxonomy(\'cat\', array(\'post\'), $args);
}
add_action( \'init\' , \'custom_taxonomies\' );