Function Reference: geodir_icl_duplicate_taxonomies
Summary
Duplicate post taxonomies for WPML translation post.
Global Values
- $sitepress
- (object) (required) Sitepress WPML object.
- Default: None
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
Parameters
- $master_post_id
- (int) (required) Original Post ID.
- Default: None
- $tr_post_id
- (int) (required) Translation Post ID.
- Default: None
- $lang
- (string) (required) Language code for translating post.
- Default: None
Return Values
- (bool)
- True for success, False for fail.
Change Log
Since: 1.5.0
Filters
‘translate_object_id’ [Line: 2700]
Source File
geodir_icl_duplicate_taxonomies() is located in geodirectory-functions/custom_functions.php [Line: 2687]
Source Code
function geodir_icl_duplicate_taxonomies($master_post_id, $tr_post_id, $lang) {
global $sitepress, $wpdb;
$post_type = get_post_type($master_post_id);
remove_filter('get_term', array($sitepress,'get_term_adjust_id')); // AVOID filtering to current language
$taxonomies = get_object_taxonomies($post_type);
foreach ($taxonomies as $taxonomy) {
$terms = get_the_terms($master_post_id, $taxonomy);
$terms_array = array();
if ($terms) {
foreach ($terms as $term) {
$tr_id = apply_filters( 'translate_object_id',$term->term_id, $taxonomy, false, $lang);
if (!is_null($tr_id)){
// not using get_term - unfiltered get_term
$translated_term = $wpdb->get_row($wpdb->prepare("
SELECT * FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id = t.term_id WHERE t.term_id = %d AND x.taxonomy = %s", $tr_id, $taxonomy));
$terms_array[] = $translated_term->term_id;
}
}
if (!is_taxonomy_hierarchical($taxonomy)){
$terms_array = array_unique( array_map( 'intval', $terms_array ) );
}
wp_set_post_terms($tr_post_id, $terms_array, $taxonomy);
if ($taxonomy == $post_type . 'category') {
geodir_set_postcat_structure($tr_post_id, $post_type . 'category');
}
}
}
}