file. 2. Locate the SQL query around line 88. 3. Replace the existing SQL query with the following code, which includes a filter for the current language:
$current_language = apply_filters( 'wpml_current_language', NULL ); <br /> $sql = "<br /> SELECT l.ID, post_title, post_name, post_parent, post_date, post_type, l.post_modified<br /> FROM (<br /> SELECT DISTINCT p.ID, p.post_modified FROM {$wpdb->posts} as p<br /> LEFT JOIN {$wpdb->postmeta} AS pm ON ( p.ID = pm.post_id AND pm.meta_key = 'rank_math_robots' )<br /> INNER JOIN {$wpdb->prefix}icl_translations AS icl ON ( p.ID = icl.element_id AND icl.language_code = %s AND icl.element_type LIKE 'post_%' )<br /> WHERE (<br /> ( pm.meta_key = 'rank_math_robots' AND pm.meta_value NOT LIKE '%noindex%' ) OR<br /> pm.post_id IS NULL<br /> )<br /> AND p.post_type IN ( %s ) AND p.post_status IN ( '" . join( "', '", esc_sql( $statuses ) ) . "' )<br /> ORDER BY p.post_modified DESC<br /> ) o<br /> JOIN {$wpdb->posts} l ON l.ID = o.ID " . $get_child . " ORDER BY " . $sort['field'] . " " . $sort['order']; // phpcs:ignore<br /> $sql = $wpdb->prepare($sql, $current_language, $post_type);<br /> return $wpdb->get_results( $sql ); // phpcs:ignore
4. Remember that Rank Math uses cache, so you may need to reset your sitemaps after making this change. To do this, go to Rank Math SEO > Sitemaps settings, modify a setting, revert the change, and save it.
Please note that this solution might be outdated or not applicable to your case. If it doesn't help, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the issue persists, please open a new support ticket with us.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
It seems RankMath is using a SQL in order to load the posts when using the [rank_math_html_sitemap] shortcode. You can modify it as follows which seems to work fine:
- Open .../wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/html-sitemap/class-posts.php file.
- Look for line 88.
$sql = "
SELECT l.ID, post_title, post_name, post_parent, post_date, post_type, l.post_modified
FROM (
SELECT DISTINCT p.ID, p.post_modified FROM {$wpdb->posts} as p
LEFT JOIN {$wpdb->postmeta} AS pm ON ( p.ID = pm.post_id AND pm.meta_key = 'rank_math_robots' )
WHERE (
( pm.meta_key = 'rank_math_robots' AND pm.meta_value NOT LIKE '%noindex%' ) OR
pm.post_id IS NULL
)
AND p.post_type IN ( '" . $post_type . "' ) AND p.post_status IN ( '" . join( "', '", esc_sql( $statuses ) ) . "' )
ORDER BY p.post_modified DESC
)
o JOIN {$wpdb->posts} l ON l.ID = o.ID " . $get_child . " ORDER BY " . $sort['field'] . " " . $sort['order']; // phpcs:ignore
return $wpdb->get_results( $wpdb->prepare( $sql ) ); // phpcs:ignore
- For:
$current_language = apply_filters( 'wpml_current_language', NULL );
$sql = "
SELECT l.ID, post_title, post_name, post_parent, post_date, post_type, l.post_modified
FROM (
SELECT DISTINCT p.ID, p.post_modified FROM {$wpdb->posts} as p
LEFT JOIN {$wpdb->postmeta} AS pm ON ( p.ID = pm.post_id AND pm.meta_key = 'rank_math_robots' )
INNER JOIN {$wpdb->prefix}icl_translations AS icl ON ( p.ID = icl.element_id AND icl.language_code = %s AND icl.element_type LIKE 'post_%' )
WHERE (
( pm.meta_key = 'rank_math_robots' AND pm.meta_value NOT LIKE '%noindex%' ) OR
pm.post_id IS NULL
)
AND p.post_type IN ( %s ) AND p.post_status IN ( '" . join( "', '", esc_sql( $statuses ) ) . "' )
ORDER BY p.post_modified DESC
) o
JOIN {$wpdb->posts} l ON l.ID = o.ID " . $get_child . " ORDER BY " . $sort['field'] . " " . $sort['order']; // phpcs:ignore
$sql = $wpdb->prepare($sql, $current_language, $post_type);
return $wpdb->get_results( $sql ); // phpcs:ignore
Keep in mind that Rank Math use cache, so you may need to reset your sitemaps. You can do that, going to Rank Math SEO > Sitemaps settings, modify a setting, change it again and save it.
Kindly get back to us with the result if it works for you.
This is a temporary workaround, if it works for you we will need to create an errata for this and be in contact with RankMath to solve the issue as it needs to be done on their part as you see.
So yes if you apply this fix, it will be overwritten if you update RankMath.
We mentioned why it is not working originally because this is a direct SQL entry by the code they use and we do not have any control over that.
I'd appreciate it if you can confirm that this temporary workaround works for you or not.
You know with all due respect I am afraid to go there in the code. Especcialy if it will be overwritten in next update.
Once it worked for you, could you then just please create an errata for this and be in contact with RankMath to solve the issue as it needs to be done on their part.
I will just draft this page untill Rank Math fixes it and then implement it.
Did you have to ask Rank Math about any other issues before? Do they open for accepting their "bugs" and change it. If yes how long did it take them to make a change to fix it?
We already tested that on a clean WordPress installation and it worked.
I do not have an answer for the other questions as I do not have enough information about.
As a general rule of thumb, RankMath developers are very responsive but we do not have any information or guarantee when it will be released on their side after report.
By the way it is not a bug on their side, it is a matter of choice they have to implement the shortcode which is not compatible with WPML.