2016-12-27 10 views
0

投稿が作成されると、投稿と同じ名前の正確なTAXの用語も作成されるように機能が必要です。WordPress関数:投稿名と同じ名前の用語を作成しますが、用語に投稿を割り当てる必要があります

また、同じ期間にその投稿を自動的に割り当てる必要があります。

どうすればいいですか?

function add_new_term_clubes() { 
    $args = array(
     'posts_per_page' => -1, 
     'post_type'   => 'clubes' 
    ); 
    $title_query = get_posts('numberposts=-1&post_type=clubes'); 

    foreach ($title_query as $single_post) { 

     $title = get_the_title($single_post->ID); 
     $taxonomy = 'clubes_dd'; 
     $exist = term_exists($title, $taxonomy); 

      if ($exist == FALSE) 
       { 
       wp_insert_term($title, 'clubes_dd'); 

     } 
} 
} 
add_action('init','add_new_term_clubes'); 

答えて

0
function add_new_term_clubes() { 
    $args = array(
     'posts_per_page' => -1, 
     'post_type'   => 'clubes' 
    ); 
    $title_query = get_posts('numberposts=-1&post_type=clubes'); 

    foreach ($title_query as $single_post) { 

     $title = get_the_title($single_post->ID); 
     $taxonomy = 'clubes_dd'; 
     $exist = term_exists($title, $taxonomy); 

      if ($exist == FALSE) 
       { 
       wp_insert_term($title, 'clubes_dd'); 
       wp_set_post_terms($single_post->ID, $title, $taxonomy, true) 

     } 
} 
} 
:以下は、私が試した関数であります
関連する問題