2011-08-18 4 views
1

get_categories 함수에 필터를 추가하고 싶습니다.워드 프로세서의 필터 카테고리

function wpr_cat_filter($args) { 
    $args['include'] = '37'; 
    return $args; 
} 
add_filter('get_categories','wpr_cat_filter'); 

했지만, 제대로 동작하지 않습니다

나는이 시도. 무엇이 잘못 되었습니까?

+0

wp-content/plugins에 설치하고 관리자 패널에서 활성화 했습니까? 이걸 어떻게 시험해? – MGwynne

+0

예, 플러그인이 plugins 디렉토리에 있으며 활성화되었습니다. 이를 테스트하기 위해 페이지를 생성하고 get_categories() 출력을 표시했습니다. –

답변

0

필터가 실제로 적용된 것 같지 않습니다.

당신이 (에/category.php을 WP-포함)은 "get_categories"기능을 선택하면 적용되지 "get_categories"필터가 없습니다 :

wordpress$ grep -Ri "apply_filters" * | grep get_categories 
wp-includes/default-widgets.php:   wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args)); 
wp-includes/default-widgets.php:  wp_list_categories(apply_filters('widget_categories_args', $cat_args)); 
wp-includes/category.php: $taxonomy = apply_filters('get_categories_taxonomy', $args['taxonomy'], $args); 
: 원본을 확인하는 경우

function &get_categories($args = '') { 
     $defaults = array('taxonomy' => 'category'); 
     $args = wp_parse_args($args, $defaults); 

     $taxonomy = apply_filters('get_categories_taxonomy', $args['taxonomy'], $args); 

     // Back compat 
     if (isset($args['type']) && 'link' == $args['type']) { 
       _deprecated_argument(__FUNCTION__, '3.0', ''); 
       $taxonomy = $args['taxonomy'] = 'link_category'; 
     } 

     $categories = (array) get_terms($taxonomy, $args); 

     foreach (array_keys($categories) as $k) 
       _make_cat_compat($categories[$k]); 

     return $categories; 
} 

는 또한

아마도 직접 추가 할 수도 있고 나중에 추가 할 수도있는 필터의 자리 표시 자일 수도 있습니다. 당신이 필터를 원하는 경우

get_category 기능을 변경 :

function &get_categories($args = '') { 
     $defaults = array('taxonomy' => 'category'); 
     $args = wp_parse_args($args, $defaults); 
     $args = apply_filters('get_categories', $args); 

     $taxonomy = apply_filters('get_categories_taxonomy', $args['taxonomy'], $args); 

     // Back compat 
     if (isset($args['type']) && 'link' == $args['type']) { 
       _deprecated_argument(__FUNCTION__, '3.0', ''); 
       $taxonomy = $args['taxonomy'] = 'link_category'; 
     } 

     $categories = (array) get_terms($taxonomy, $args); 

     foreach (array_keys($categories) as $k) 
       _make_cat_compat($categories[$k]); 

     return $categories; 
} 

당신이 필터가 적용되지 않는 이유를 찾기 위해 워드 프레스에 버그를 신고하거나 메일 링리스트에 문의 할 수 있습니다!

관련 문제