在我进行了一点挖掘之后,我在家长主题中找到了正确的行动。函数看起来是这样的(实际上正是示例Ilinked 以上内容):
//////////////////////////////
// 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\');