You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a post is localized to the default language, Polylang does not include a 'lang' parameter in a singular main query with URL modification settings described in the attached screenshot. This causes a redirect to incorrect language if there are localized posts with the same post name and the query randomly matches to an indexed post localized to other than the default language.
This could be fixed by filtering the WP query before RediSearch does its query and adding the missing language parameter. Here's an example of adding the missing locale:
\add_action( 'redipress/before_search',
/** * Fix localization for main queries on default language. * * @param Search $search The search instance. * @param \WP_Query $wp_query The query instance. */function( $search, $wp_query ) {
if ( $wp_query->is_main_query() ) {
// If this is not a singular page, bail early.if ( ! $wp_query->is_singular ) {
return;
}
// If a language is set in query vars, bail early.if ( ! empty( $wp_query->query_vars['lang'] ) || ! empty( $wp_query->query['lang'] ) ) {
return;
}
// If the post type is not translated, bail early.if (
function_exists( 'pll_is_translated_post_type' ) &&
! pll_is_translated_post_type( $wp_query->get( 'post_type' ) )
) {
return;
}
$tax_queries = $wp_query->get( 'tax_query' ) ?: [];
// Try to find the language query.$lang_set = false;
foreach ( $tax_queriesas$idx => $tax_query ) {
$taxonomy = $tax_query['taxonomy'] ?? '';
if ( $taxonomy === 'language' ) {
$lang_set = true;
}
}
// If no lang set, set the default language.if ( ! $lang_set && function_exists( 'pll_default_language' ) ) {
$tax_queries[] = [
'taxonomy' => 'language',
'field' => 'slug',
'terms' => [ pll_default_language() ],
'operator' => 'IN',
];
}
// Recreate the tax queries.$wp_query->tax_query = new \WP_Tax_Query( $tax_queries );
}
},
1, 2
);
URL modifications settings
The text was updated successfully, but these errors were encountered:
If a post is localized to the default language, Polylang does not include a 'lang' parameter in a singular main query with URL modification settings described in the attached screenshot. This causes a redirect to incorrect language if there are localized posts with the same post name and the query randomly matches to an indexed post localized to other than the default language.
This could be fixed by filtering the WP query before RediSearch does its query and adding the missing language parameter. Here's an example of adding the missing locale:
URL modifications settings
The text was updated successfully, but these errors were encountered: