我注意到,按照以下方法,我的自定义分类过滤器在3.3.1管理中不再工作:Adding a Taxonomy Filter to Admin List for a Custom Post Type?
我还发现,要过滤分类法,查询字符串需要&taxonomy=whatever
和&term=something
待通过。有没有人在这方面有经验,可以提供哪些解决方案?
以下是问题中的一些代码作为示例:
add_action(\'restrict_manage_posts\',\'restrict_listings_by_business\');
function restrict_listings_by_business() {
global $typenow;
global $wp_query;
if ($typenow==\'listing\') {
$taxonomy = \'business\';
$business_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
\'show_option_all\' => __("Show All {$business_taxonomy->label}"),
\'taxonomy\' => $taxonomy,
\'name\' => \'business\',
\'orderby\' => \'name\',
\'selected\' => $wp_query->query[\'term\'],
\'hierarchical\' => true,
\'depth\' => 3,
\'show_count\' => true, // Show # listings in parens
\'hide_empty\' => true, // Don\'t show businesses w/o listings
));
}
}
以及
add_filter(\'parse_query\',\'convert_business_id_to_taxonomy_term_in_query\');
function convert_business_id_to_taxonomy_term_in_query($query) {
global $pagenow;
$qv = &$query->query_vars;
if ($pagenow==\'edit.php\' &&
isset($qv[\'taxonomy\']) && $qv[\'taxonomy\']==\'business\' &&
isset($qv[\'term\']) && is_numeric($qv[\'term\'])) {
$term = get_term_by(\'id\',$qv[\'term\'],\'business\');
$qv[\'term\'] = $term->slug;
}
}
SO网友:Stephen Harris
您的代码有几处错误。。。
过滤时,它不是term
这给出了术语的ID,但是business
(在本例中),因为这是您为下拉菜单提供的名称。替换的所有实例term
具有business
筛选时未设置分类法。从中删除此支票parse_query
功能以下内容对我很有用(除了我将“列出”改为“发布”)。。。
add_action(\'restrict_manage_posts\',\'restrict_listings_by_business\');
function restrict_listings_by_business() {
global $typenow;
global $wp_query;
if ($typenow==\'post\') {
$taxonomy = \'business\';
$term = isset($wp_query->query[\'business\']) ? $wp_query->query[\'business\'] :\'\';
$business_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
\'show_option_all\' => __("Show All"),
\'taxonomy\' => $taxonomy,
\'name\' => \'business\',
\'orderby\' => \'name\',
\'selected\' => $term,
\'hierarchical\' => true,
\'depth\' => 3,
\'show_count\' => true, // Show # listings in parens
\'hide_empty\' => true, // Don\'t show businesses w/o listings
));
}
}
add_filter(\'parse_query\',\'convert_business_id_to_taxonomy_term_in_query\');
function convert_business_id_to_taxonomy_term_in_query($query) {
global $pagenow;
$qv =& $query->query_vars;
if ($pagenow==\'edit.php\' && isset($qv[\'business\']) && is_numeric($qv[\'business\'])) {
$term = get_term_by(\'id\',$qv[\'business\'],\'business\');
$qv[\'business\'] = ($term ? $term->slug : \'\');
}
}