algoliasearch-wordpress
algoliasearch-wordpress copied to clipboard
WPML translated facets
What did you expect to happen?
translated text for the post_type_label facet.
What happened instead?
It always shows the main language text
How can we reproduce this behavior?
setup a simple index with wpml enabled and followed the wpml instructions here: https://community.algolia.com/wordpress/wpml.html
Technical info
- WordPress version: 4.9.8
- Algolia Search plugin version: 2.11.2
I have the same Issue. The post_type_label is not being translated.
Technical WordPress 5.1 Algolia 2.11.3 WPML 4.2.4.1
Also got this mind numbing issue: Wordpress : 5.1 WPML: 4.2.0 Algolia 2.11.3
I have fixed a temporary solution fix that works great.
function shared_attributes(array $attributes, WP_Post $post){
$lang = '';
// WPML is active, set correct language
if(function_exists('icl_object_id')){
global $sitepress;
$lang = $sitepress->get_current_language();
}
$attributes['wpml'] = apply_filters('wpml_post_language_details', null, $post->ID);
// If post post type index the following
if('post' == $post->post_type){
$attributes['post_type_label'] = ($lang == 'en') ? 'Articles' : 'Artikler';
}
// If service post type index the following
if('service' == $post->post_type){
$attributes['post_type_label'] = ($lang == 'en') ? 'Services' : 'Tjenester';
}
}
function posts_index_settings(array $settings){
$settings['attributesForFaceting'][] = 'wpml.locale';
return $settings;
}
add_filter('algolia_searchable_post_shared_attributes', 'shared_attributes', 10, 2); // sharing attributes
add_filter('algolia_searchable_posts_index_settings', 'posts_index_settings'); // indexing settings
As you can see we change the post_type_label
attribute and when indexing the results the languages are separated from eachother in Algolia. The English version is indexed within the english labels and the other language is indexed on its language.
This works perfectly.