+3 votes
in CMS Tips by (60.1k points)
I am using Yoast SEO plugin, which also generates a sitemap for the website. However, the posts in the post sitemap are not sorted in the descending order of the modified date, i.e., the latest post is always at the bottom of the sitemap. How can I sort the posts in the descending order of the modified date?

1 Answer

+2 votes
by (355k points)
selected by
 
Best answer
There is no option in the user interface of the Yoast plugin to sort the posts in the descending order of the modified date. You need to make a small change in the following PHP code: class-post-type-sitemap-provider.php
This code should be in the following folder of the WordPress installation.

wp-content/plugins/wordpress-seo/inc/sitemaps

Open the file in an editor and search for the term "order by". There should be two instances of the term. To sort the posts in descending order, you need to replace ASC with DESC.

ORDER BY post_modified_gmt DESC

ORDER BY {$wpdb->posts}.post_modified DESC LIMIT %d OFFSET %d


...