RESTRICE_MANAGE_POST在3.3.1中不起作用

时间:2012-02-21 作者:Niels

我注意到,按照以下方法,我的自定义分类过滤器在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;
    }
}

1 个回复
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 : \'\');
    }
}

结束

相关推荐

changing wp-admin/widgets.php

我们希望在管理面板中设计小部件页面时有所不同,主要是为了帮助站点管理员了解每个小部件在站点中的显示位置:为此,我们需要更改小部件所使用的HTML。php呈现(仅仅更改css是不够的)。我们如何在不触及核心的情况下做到这一点?