2014-10-13 3 views
0

게시물에 일치하는 용어가있는 경우 카테고리에 게시물을 할당하는 간단한 함수가 있습니다 (save_post 사용). 문제는 하나의 용어로 작동하지만 여러 용어를 일치시키려는 것이 효과가 없다는 것입니다. 이 작품 : WordPress의 모든 태그와 일치

function categorize_from_tags($post_id) { 

    $cat_boosted = 'cat-boosted'; 
    $terms = 'twin-turbo'; 

    if(has_term($terms, 'post_tag')) { 
     wp_set_object_terms($post_id, $cat_boosted, 'category', true); 
    } 

} 
add_action('save_post', 'categorize_from_tags', 120, 1); 

내가 여러 조건을 추가

, 그것은 작동하지 않습니다 당신은 ', UGR 트윈 터보'의 범주 이름에 보내는

function categorize_from_tags($post_id) { 

    $cat_boosted = 'cat-boosted'; 
    $terms = 'twin-turbo,ugr'; // Adding more than one term 

    if(has_term($terms, 'post_tag')) { 
     wp_set_object_terms($post_id, $cat_boosted, 'category', true); 
    } 

} 
add_action('save_post', 'categorize_from_tags', 120, 1); 

답변

3

.

은 당신과 같이 배열에 보낼 :

$terms = ['twin-turbo','ugr']; 

당신이 사용하려고하는 WP 글로벌 함수의 매개 변수를 확인해야합니다.

has_term은 일치시킬 문자열 또는 문자열 배열을 허용합니다.

+0

감사! 완벽하게 작동합니다. –

관련 문제