WordPress函数:创建一个术语,其名称与文章名称相同,但也应将文章分配给术语
我需要的功能,以便当一个职位被创建时,一个与职位名称相同的确切税务术语也被创建 我还需要自动将该帖子分配给同一个术语 我该怎么做?下面是我尝试过的函数:WordPress函数:创建一个术语,其名称与文章名称相同,但也应将文章分配给术语,wordpress,function,taxonomy,posts,Wordpress,Function,Taxonomy,Posts,我需要的功能,以便当一个职位被创建时,一个与职位名称相同的确切税务术语也被创建 我还需要自动将该帖子分配给同一个术语 我该怎么做?下面是我尝试过的函数: function add_new_term_clubes() { $args = array( 'posts_per_page' => -1, 'post_type' => 'clubes' ); $title_query = get_posts('n
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');
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 )
}
}
}