Search Across All Languages With Polylang
Makes the site search return results from every Polylang language instead of only the current one, so visitors find content that has not been translated yet.
Opens WPIDE on
Code
add_action( 'pre_get_posts', function ( $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() && function_exists( 'pll_current_language' ) ) {
$query->set( 'lang', '' );
}
} );
Notes
Each result still links to the post in its own language.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.