我想在下拉列表中显示我的自定义分类法的帖子,我的意思是我在自定义帖子类型中为分类法创建一个过滤器。我有两种不同的类型,其中包含一些子类别&;在这个类别中,我添加了一些帖子,第一个分类法是;“类型”;第二个是;类别“;,因此,当我单击轴名下拉列表并选择用于显示帖子的子类别时,不会显示任何内容。。。
函数diwp\\U arts\\U custom\\U post\\U type(){
$labels = array(
\'name\' => \'Arts\',
\'singular_name\' => \'Art\',
\'add_new\' => \'Add New Post\',
\'add_new_item\' => \'Enter Art Details\',
\'all_items\' => \'All Arts\',
\'featured_image\' => \'Add Feature Image\',
\'set_featured_image\' => \'Set Feature Image\',
\'remove_featured_image\' => \'Remove Feature Image\'
);
$args = array(
\'public\' => true,
\'label\' => \'Arts\',
\'labels\' => $labels,
\'description\' => \'Arts is a collection of all Art and their info\',
\'menu_icon\' => \'dashicons-art\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\'),
\'capability_type\' => \'page\',
);
register_post_type(\'arts\', $args);
}
add\\u action(\'init\',\'diwp\\u arts\\u custom\\u post\\u type\');
函数wpdocs\\u create\\u book\\u tax(){注册\\u分类法(\'Types\',\'arts\',数组(\'label\',\'Types\',\'textdomain\'),\'rewrite\',\'array(\'slug\',\'arts\'),\'hierarchy\',\'true,);
register_taxonomy( \'Categories\', \'arts\', array(
\'label\' => __( \'Categories\', \'textdomain\' ),
\'rewrite\' => array( \'slug\' => \'arts\' ),
\'hierarchical\' => true,
) );
}
添加\\u操作(\'init\',\'wpdocs\\u create\\u book\\u tax\',0);
函数get\\u terms\\u dropdown\\u grade\\u level($taxonomies,$args){$myterms=get\\u terms($taxonomies,$args);$output=”;//我可以更改此名称(对于我的remembreance)!$output。=”选择类型“;foreach($terms为$term){$root\\u url=get\\u bloginfo(\'url”)$term\\u分类法=$term->;分类学$term\\u slug=$term->;段塞$term\\u name=$term->;名称$链接=$term\\u slug$输出="E"E$term\\u名称"E";;}$输出="E&引用;;返回$输出;}
function get_terms_dropdown_type($taxonomies, $args){
$myterms = get_terms($taxonomies, $args);
$output ="<select name=\'Categories\'>";
$output .="<option value=\'\'>Select Categories</option>";
foreach($myterms as $term){
$root_url = get_bloginfo(\'url\');
$term_taxonomy=$term->taxonomy;
$term_slug=$term->slug;
$term_name =$term->name;
$link = $term_slug;
$output .="<option value=\'".$link."\'>".$term_name."</option>";
}
$output .="</select>";
return $output;
}
我将此代码写入侧栏。php文件,因为我想在所有页面上显示下拉列表:
“method=”get“>”name“,”hide\\u empty“=>false);$select=get\\u terms\\u dropdown\\u grade\\u level($分类法,$args);$select=preg\\u replace(“\\]*)>”,“”,$select);echo$select;?>”name“,”hide\\u empty“=>false);$select=get\\u terms\\u dropdown\\u type($分类法,$args);
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange=\'return this.form.submit()\'>", $select);
echo $select;
?>
<input type="submit" name="submit" value="Go" />
</div>