Last active
September 10, 2018 14:45
-
-
Save benlbot/4324f23a3b21a4e61beb52c57cceb7dc to your computer and use it in GitHub Desktop.
This function allow to translate (query translated objects) your ACF relationship fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/************************************************************************************************** | |
* | |
* ACF / WPML translate relationship fields | |
* | |
*************************************************************************************************/ | |
add_filter( 'wpml_duplicate_generic_string', 'my_override_post_duplication', 10, 3 ); | |
function my_override_post_duplication( $value_to_filter, $target_language, $meta_data ) { | |
if ( isset($_POST['icl_ajx_action']) && $_POST['icl_ajx_action'] == "make_duplicates"){ | |
if ( $meta_data[ 'context' ] == "custom_field" && $value_to_filter !== '' && $meta_data[ 'key' ][0] !== '_') { | |
$field = get_field_object($meta_data[ 'key' ], $meta_data[ 'master_post_id' ]); | |
if ( $field['type'] == 'relationship' && $meta_data[ 'attribute' ] == 'value' ) { | |
if ( $meta_data[ 'is_serialized' ] ) { | |
$values = unserialize($value_to_filter); | |
$new_values = array(); | |
foreach ($values as $value){ | |
$post_type = get_post($value)->post_type; | |
$new_values[] = apply_filters( 'wpml_object_id', intval( $value ), $post_type, false, $target_language ); | |
} | |
$value_to_filter = serialize($new_values); | |
} | |
} | |
} | |
} | |
return $value_to_filter; | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment