Creating two subterms for parent term in taxonomy software-developers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Creating two subterms for parent term in taxonomy "software-developers" while publishing parent term
// Prefix tt_t_sd_ - two terms to software-developers
function subterms_for_software_term( $term_id, $tt_id ) {
$tt_t_sd_tax = 'software-developers'; // Назначаем таксоносию для проверки
$tt_t_sd_tax_by = get_term_by( 'id', $tt_id, $tt_t_sd_tax ); // Подготовка функции для получения данных по ID созданного вручную тёрма
if ( is_admin() && $tt_t_sd_tax_by->taxonomy === 'software-developers' && $tt_t_sd_tax_by->parent == '0' ) {
/* $tt_t_sd_parent_name = $tt_t_sd_tax_by->name; // Получаем имя создаваемого вручную тёрма
var_dump($tt_t_sd_parent_name); die;*/
if(!is_wp_error($tt_t_sd_tax_by)) {
wp_insert_term(
$tt_t_sd_tax_by->name.' Bonuses',
$tt_t_sd_tax,
array(
'description' => '',
'parent' => $tt_id,
'slug' => 'bonuses-'.$tt_t_sd_tax_by->slug,
)
);
delete_option($tt_t_sd_tax."_children");
wp_cache_flush();
wp_insert_term(
$tt_t_sd_tax_by->name.' Free Games',
$tt_t_sd_tax,
array(
'description' => '',
'parent' => $tt_id,
'slug' => 'free-games-'.$tt_t_sd_tax_by->slug,
)
);
delete_option($tt_t_sd_tax."_children");
wp_cache_flush();
}
}
}
add_action( 'created_term', 'subterms_for_software_term', 10, 3 );