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
This issue is fixed. Updating to the latest version solves it on your site, so you only need this workaround if you can’t update yet.
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:
With that block:PHP
// 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; } } }
PHP// 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