Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#52727 closed defect (bug) (worksforme)

wp_sitemaps_max_urls

Reported by: pvde's profile pvde Owned by:
Milestone: Priority: normal
Severity: minor Version: 5.6.2
Component: Sitemaps Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Hello, The function to have more entries in one sitemap doesn't work.

I use this custom made code:

add_filter( 'wp_sitemaps_max_urls', 'filter_function_name_9755', 10, 2 );
function filter_function_name_9755( $max_urls, $object_type ){
	// filter...

	return $max_urls;
}
return apply_filters( 'wp_sitemaps_max_urls', 1000, $object_type );

But nothing happens. In fact, it messes up the entire sitemap.

Change History (6)

#1 @SergeyBiryukov
3 years ago

  • Description modified (diff)

#2 @SergeyBiryukov
3 years ago

  • Keywords reporter-feedback added

Hi there, welcome to WordPress Trac! Thanks for the report.

In your example, the filter_function_name_9755() function just returns the original result, and the second return line is for some reason outside of the function. Moving it inside the function as is would not exactly work either, as the apply_filters() call is not needed there and would lead to endless recursion.

Does it work if you rewrite it like this?

add_filter( 'wp_sitemaps_max_urls', 'filter_function_name_9755', 10, 2 );
function filter_function_name_9755( $max_urls, $object_type ){
	return 1000;
}

#3 @pvde
3 years ago

You are a genius.It worked!

#4 @pvde
3 years ago

Just one last question if you have the time.
I try to exclude this sitemap
wp-sitemap-taxonomies-category-1.xml

<?php
add_filter(
    'wp_sitemaps_taxonomies',
    function( $taxonomies ) {
        unset( $taxonomies['categories'] );
        return $taxonomies;
    }
);

It doesn't remove

#5 @pvde
3 years ago

Ahh wait categories --> category

#6 @swissspidy
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.