function terms_for_casino_tax post if is_admin in_category 245 post- I

 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function terms_for_casino_tax( $post ) {
if ( is_admin() && in_category( 245, $post->ID ) ) {
$casino_post = get_post($post->ID); // Получаем массив данных текущего обзора казино
$term_slug = $casino_post->post_name; // Слаг для нового тёрмса
$taxonomy = 'online-casinos';
if ( term_exists( $term_slug, 'online-casinos', '' ) ) { // Проверяем существует тёрм или нет
return;
} else {
$casino_title = $casino_post->post_title;
wp_insert_term(
$casino_title,
$taxonomy,
array(
'description' => '',
'parent' => 0,
'slug' => $term_slug
)
);
$parent_term_id = $term_slug['term_id'];
/*delete_option($taxonomy.'_children');*/
delete_option("$casino_title");
wp_cache_flush();
wp_insert_term(
$casino_title.' Articles',
$taxonomy,
array(
'description' => '',
'parent' => $parent_term_id,
'slug' => $term_slug.'-articles'
)
);
delete_option("$casino_title.' Articles'");
wp_cache_flush();
wp_insert_term(
$casino_title.' Bonuses',
$taxonomy,
array(
'description' => '',
'parent' => $parent_term_id,
'slug' => $term_slug.'-bonuses'
)
);
delete_option("$casino_title.' Bonuses'");
wp_cache_flush();
wp_insert_term(
$casino_title.' Complaints',
$taxonomy,
array(
'description' => '',
'parent' => $parent_term_id,
'slug' => $term_slug.'-complaints'
)
);
delete_option("$casino_title.' Complaints'");
wp_cache_flush();
}
}
}
add_action( 'publish_post', 'terms_for_casino_tax', 10, 2 );