我使用的主题是自定义分类法( 未登记 ):
function wpse314876_unregister_taxonomy() {
unregister_taxonomy_for_object_type( 'page_category', 'page' );
}
add_action( 'init', 'wpse314876_unregister_taxonomy' );但是在“所有页面概览”(/wp-admin/edit.php?post_type=page)中,它仍然显示一个空的下拉筛选列表。我可以删除所有类别下拉列表。,但这不是我想要的,因为我已经添加了自定义下拉分类法筛选器列表。了。
下拉列表显示为一个小空列表。

它的HTML看起来是这样:
我如何才能删除什么空下拉列表?
发布于 2018-09-22 21:30:03
经过我的小挖掘,我找到了正确的行动在家长的主题。这个函数看起来是这样的(实际上就是上面的示例i 连系 ):
//////////////////////////////
// Add page category filter //
//////////////////////////////
add_action('restrict_manage_posts', 'uncode_page_filter_post_type_by_taxonomy');
function uncode_page_filter_post_type_by_taxonomy() {
global $typenow;
$post_type = 'page'; // change to your post type
$taxonomy = 'page_category'; // change to your taxonomy
if ($typenow == $post_type) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => sprintf(esc_html__("Show All %s", 'uncode'), $info_taxonomy->label),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name',
'selected' => $selected,
'show_count' => true,
'hide_empty' => true,
));
};
}
add_filter('parse_query', 'uncode_page_convert_id_to_term_in_query');
function uncode_page_convert_id_to_term_in_query($query) {
global $pagenow;
$post_type = 'page'; // change to your post type
$taxonomy = 'page_category'; // change to your taxonomy
$q_vars = &$query->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
$term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
$q_vars[$taxonomy] = $term->slug;
}
}为了删除它们,我在我的子主题remove_action()中添加了一个简单的function.php。
/**
* Remove page_category filter and parse query
*
**/
remove_action('restrict_manage_posts', 'uncode_page_filter_post_type_by_taxonomy');
remove_action('parse_query', 'uncode_page_convert_id_to_term_in_query');https://wordpress.stackexchange.com/questions/314876
复制相似问题