Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing an issue where the

[rank_math_html_sitemap]

shortcode is displaying all pages, including those in the original and translated languages, we have a solution for you.
Solution:
1. Open the

.../wp-content/plugins/seo-by-rank-math/includes/modules/sitemap/html-sitemap/class-posts.php

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.

Our next available supporter will start replying to tickets in about 5.62 hours from now. Thank you for your understanding.

Tagged: 

This topic contains 8 replies, has 2 voices.

Last updated by Christopher Amirian 3 months ago.

Assisted by: Christopher Amirian.

Author Posts
February 4, 2024 at 11:55 am #15263417

ylyasK

[rank_math_html_sitemap] shortcode prints all pages including the original and translated languages

February 4, 2024 at 2:32 pm #15263604

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

The issue is reported to the compatibility team. I will get back to you as soon as I have an update.

Thank you.

February 6, 2024 at 2:30 pm #15272357

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

I have an answer from the second tier support:

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.

Thanks.

February 6, 2024 at 3:07 pm #15272539

ylyasK

I will try and let you know the results.

I hope it won't affect my site negatively in terms of speed perfomance, SEO, common compatability with WordPress itself and other plugins.

And what about Rank Math updates. What if Rank Math's as well as any other plugin next update won't be compatible with this source code change.

And do I have to do something in code again regularly to maintain this new feature?

Actually I am a bit afraid to make such change, it seems like something invisibly can be hurt or turn out to break later

February 7, 2024 at 6:47 am #15274602

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

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.

Thanks.

February 7, 2024 at 1:22 pm #15276755

ylyasK

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?

February 10, 2024 at 8:04 am #15288079

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Hi there,

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.

Thanks.

February 10, 2024 at 8:20 am #15288082

ylyasK

Yes that is not a bug, that is why I cited it. Do they open for accepting "change offers". Have they done it before?

February 10, 2024 at 1:28 pm #15288551

Christopher Amirian
Supporter

Languages: English (English )

Timezone: Asia/Yerevan (GMT+04:00)

Yes and they have a dedicated page for WPML:

hidden link

February 10, 2024 at 6:57 pm #15288950

ylyasK

Okay. Thank you. I hope you already send them and errata for this little change from their side.

ylyasK confirmed that the issue was resolved on 2024-02-10 18:57:50.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.