Resolved
Reported for: WPML Multilingual CMS 3.1.9.5
Resolved in: 3.2
Overview of the issue
When one or more parent pages have different children pages with the same slug, opening one of the children redirects to the wrong page.
Re-using a slug in children pages seems to cause wrong redirection on the front-end.
Example:
- Page A
- child-aa
- child-ab
- Page B
- child-aa (unique page, but same slug as 1.1)
- child-bb
Workaround
The issue will be fixed with WPML 3.2.
Meanwhile you can use the following workaround.
Please note that this only works with duplicated child slugs, as long as parents are not using the same name as children.
- Make a full backup of your website. If possible, try this first in a non production copy of your website.
- Open
sitepress.class.php
- Go to line 7804: it should contains only
// Adjust page name
- Replace this block of code (line from 7804 to 7828:
// Adjust page name if ( isset( $q->query_vars[ 'pagename' ] ) && !empty( $q->query_vars[ 'pagename' ] ) ) { // find the page with the page name in the current language. $pagename = explode ( '/', $q->query_vars[ 'pagename' ] ); $pagename = array_pop ( $pagename ); $pid = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM $wpdb->posts p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND t.element_type='post_page' WHERE p.post_name=%s AND t.language_code = %s ", $pagename, $current_language ) ); if ( $pid ) { $q->query_vars[ 'page_id' ] = $pid; // We have found the page id unset( $q->query_vars[ 'pagename' ] ); if ( $q->query_vars[ 'page_id' ] == get_option( 'page_for_posts' ) ) { // it's the blog page. $q->is_page = false; // $wp_query->is_page = false; $q->is_home = true; // $wp_query->is_home = true; $q->is_posts_page = true; // $wp_query->is_posts_page = true; } } }
With that block:
// Adjust page name if ( isset( $q->query_vars[ 'pagename' ] ) && !empty( $q->query_vars[ 'pagename' ] ) ) { // find the page with the page name in the current language. $pid = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM $wpdb->posts p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND element_type='post_page' WHERE p.post_name=%s AND t.language_code = %s ", $q->query_vars[ 'pagename' ], $current_language ) ); if ( $pid ) { $q->query_vars[ 'page_id' ] = $pid; // We have found the page id unset( $q->query_vars[ 'pagename' ] ); if ( $q->query_vars[ 'page_id' ] == get_option( 'page_for_posts' ) ) { // it's the blog page. $q->is_page = false; // $wp_query->is_page = false; $q->is_home = true; // $wp_query->is_home = true; $q->is_posts_page = true; // $wp_query->is_posts_page = true; } } }
- Save
- Reload the website
Wow. Obviously a serious bug. This really needs to get published in an update right away.
James, 3.2 provides a fix for this issue
Did not solve my problem 🙁
Hello James,
A fix for this is coming with 3.2 which is due for release early next week.
wow that is great to know!