Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hayatbiralem/252b4a810a0b4183fb42bfbd3a4e164a to your computer and use it in GitHub Desktop.
Save hayatbiralem/252b4a810a0b4183fb42bfbd3a4e164a to your computer and use it in GitHub Desktop.
WPML support for Oxygen Builder's taxonomy templates
<?php
function my_prefix_filter_ct_template_archive_among_taxonomies($metadata, $object_id, $meta_key, $single)
{
$meta_needed = 'ct_template_archive_among_taxonomies';
if (!is_admin() && isset($meta_key) && $meta_needed == $meta_key) {
remove_filter('get_post_metadata', 'my_prefix_filter_ct_template_archive_among_taxonomies', 100);
$current_meta = get_post_meta($object_id, $meta_needed, true);
add_filter('get_post_metadata', 'my_prefix_filter_ct_template_archive_among_taxonomies', 100, 4);
$default_lang = apply_filters('wpml_default_language', NULL);
$current_lang = apply_filters('wpml_current_language', NULL);
if (!empty($current_meta)) {
if ($current_lang != $default_lang) {
if (is_array($current_meta)) {
$new_meta = [];
foreach ($current_meta as $term_id) {
$term = get_term($term_id);
if ($term) {
$new_meta[] = apply_filters('wpml_object_id', $term->term_id, $term->taxonomy, TRUE, $current_lang);
}
}
return [$new_meta]; // return array of array is important because of the process around $single
}
}
}
}
return $metadata;
}
add_filter('get_post_metadata', 'my_prefix_filter_ct_template_archive_among_taxonomies', 100, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment