-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathwp_all_import_set_post_terms.php
45 lines (41 loc) · 1.56 KB
/
wp_all_import_set_post_terms.php
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
<?php
/**
* ==============================================
* Filter: wp_all_import_set_post_terms
* ==============================================
*
* Called when WP All Import is setting the post taxonomy terms.
*
* @param $term_taxonomy_ids - Array of taxonomy IDs.
* @param $tx_name - The name of the current taxonomy.
* @param $pid - The Post ID.
* @param $import_id - The current import ID.
*
* @return array
*/
add_filter( 'wp_all_import_set_post_terms', 'wpai_wp_all_import_set_post_terms', 10, 4 );
function wpai_wp_all_import_set_post_terms( $term_taxonomy_ids, $tx_name, $pid, $import_id ) {
// Code here.
}
// ----------------------------
// Example uses below
// ----------------------------
/**
* Example: Leave assigned category "Featured" in tact, even if it's not included in the import.
*
*/
add_filter( 'wp_all_import_set_post_terms', 'wpai_wp_all_import_set_post_terms', 10, 4 );
function wpai_wp_all_import_set_post_terms( $term_taxonomy_ids, $tx_name, $pid, $import_id ) {
if ( $tx_name == 'product_cat' ){
$txes_list = get_the_terms($pid, $tx_name);
if ( ! empty($txes_list) ){
foreach ($txes_list as $cat){
if ($cat->name == 'Featured'){
$term_taxonomy_ids[] = $cat->term_taxonomy_id;
break;
}
}
}
}
return $term_taxonomy_ids;
}