Open gibrown opened 6 years ago
This issue has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
Requested in 5988426-hc, the website uses Polylang and it would be nice to have the search widget compatible with this plugin.
This issue has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
Also in #16150.
Requested in 3037423-zd - leaving a comment here to follow up with them if this is fixed in the future.
I'm currently working on adding JP Instant Search to a multilingual site w/Polylang and can report that things are working nicely.
What is working:
pandemic
), French (matching pandémie
), Portuguese (matching pandemia
), Spanish (matching pandemia
).What doesn't work, but also is not promised ;-)
https://example.site?s=pandem&language=fr
So, cross-language searching and filtering is working (for me, on this site, with Polylang). There's still no settings to control the cross-language search behavior...but, I think https://jetpack.com/support/search/frequently-asked-questions/#troubleshoot-multilingual could be updated to reflect that multilingual content search does work.
I spent some time trying to get Jetpack search and Polylang to play nicely.
Here's a code snippet that made it work for me:
add_filter( 'jetpack_instant_search_options', function($options) {
$lang = pll_current_language();
$options['adminQueryFilter'] = array(
'bool' => array(
'must' => array(
array( 'term' => array( 'taxonomy.language.slug' => $lang ) ),
)
)
);
return $options;
} );
@Automattic/jetpack-search do you think we should just add this filter whenever polylang is detected? Would WPML also work this way?
do you think we should just add this filter whenever polylang is detected? Would WPML also work this way?
Assuming pll_current_language()
is returning the current user-selected language, it seems like a sensible default to adopt 👍
I was considering using Jetpack Search for our site, but the lack of WPML support unfortunately makes it not an option. :(
Support References
This comment is automatically generated. Please do not edit it.
Hello,
I have a solution by add some code in theme/function.php, and it works.
add_filter( 'jetpack_instant_search_options', function($options) { if ( function_exists( 'icl_object_id' ) ) { global $sitepress, $wpdb; $language_code = $sitepress->get_current_language(); $ids = $wpdb->get_col("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type='post_post' AND language_code='{$language_code}'"); $options['adminQueryFilter'] = array( 'bool' => array( 'must' => array( array( 'terms' => array( 'post_id' => $ids) ), ) ) ); } return $options; });
But there's another problem: the url is not correct in the search result. For example, my English site is www.example.com and my germany site is de.example.com, when I search in the germany site, the result is all germany post, but the url of the post is still www.example.com/xxx/xxx, not de.example.com/xxx/xxx
How to fix this?
I spent some time trying to get Jetpack search and Polylang to play nicely.
Here's a code snippet that made it work for me:
add_filter( 'jetpack_instant_search_options', function($options) { $lang = pll_current_language(); $options['adminQueryFilter'] = array( 'bool' => array( 'must' => array( array( 'term' => array( 'taxonomy.language.slug' => $lang ) ), ) ) ); return $options; } );
Has anyone got this code snippet to work? I've got Jetpack Search up and running on my site that uses Polylang, which then returned multiple versions of a page (language versions) within the search :( Adding this code snippet to my functions.php file resulted in nothing being returned when searching.
Hi @rjdusk I've got this working on ontherhone.com (english and french). I should maybe note that I added the code snippet via the WPCode plugin but I would be surprised if that made a difference from adding it in functions.php ...
+1, 6661488-zd-a8c, to have Jetpack Search working with WPML.
I had to uninstall the plugin as currently it lacks an integration with the multilingual plugin WPML that would allow to filter search results to the active language.
This was also brought up in #32811 (cc'ing @diiegopereira, who works on WPML and opened the issue).
+1, 7211982-zd-a8c, to have Jetpack Search working with WPML.
+1 7216357-zd-a8c, request for compatibility with Weglot.
+1 6281327-zd-a8c, compatibility with WPML
The solutions mentioned above don't work for TranslatePress because that plugin stores the translations in a custom table, not as separate posts like Polylang.
We index posts based on both the language set for the blog, and also the language detected for the post. Currently though the search will only search based on the blog's language setting. We should add a way to support/control cross language searching.
Two cases to handle on the search side:
There are also two popular multilanguage plugins we should add support for: WPML and Polylang. The indexing side of these falls under #8663, but on the search side we should also hook into how they handle search.