[wp-trac] [WordPress Trac] #51912: Sitemap pages 404 with more than one page

WordPress Trac noreply at wordpress.org
Thu Sep 18 13:26:14 UTC 2025


#51912: Sitemap pages 404 with more than one page
--------------------------+------------------------------
 Reporter:  loranrendel   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Sitemaps      |     Version:  5.5
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+------------------------------

Comment (by RavanH):

 Replying to [comment:19 phanduynam]:
 > Has anyone solved this problem?

 Hi @phanduynam, both @tigerfinch and @Tkama provided solutions above. A
 variant of a solution from @Tkama is implemented in
 https://wordpress.org/plugins/xml-sitemaps-manager/

 If you prefer a raw code snippet, try:

 {{{#!php
 <?php
 add_action( 'parse_request', 'track51912_sitemaps_loaded' );

 function track51912_sitemaps_loaded( $wp ) {
         global $wp_query;

         if ( empty( $wp->query_vars['sitemap'] ) && empty( $wp->query_vars
 ['sitemap-stylesheet'] ) ) {
                 return;
         }

         // Prepare query variables.
         $query_vars           = $wp_query->query_vars;
         $wp_query->query_vars = $wp->query_vars;

         // Render the sitemap.
         wp_sitemaps_get_server()->render_sitemaps();

         // Still here? Then it was an invalid sitemap request after all.
 Undo everything and carry on...
         $wp_query->query_vars = $query_vars;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51912#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list