Support » Fixing WordPress » [Plugin: Google XML Sitemaps] Bug in Sitemap Generation when using ‘post_link’ hook

  • Hi Arne:

    Great plugin but I’ve just come across a bug when using the the ‘post_link‘ hook. I’m working with v3.1.2 and the problem occurs with loop that starts line 1891 in sitemap-core.php where the global $post variable is not set the first time through the loop. You call get_permalink($post->ID) but unfortunately it does not pass the $post variable to the ‘post_link‘ filter, it only passes the default permalink string.

    You can recreate the problem by using this code in the functions.php file of a theme for any database that has 2 or more posts:

    add_filter('post_link', 'munge_post_link');
    function munge_post_link($permalink) {
    	global $post;
    	if (!isset($post))
    		return $permalink;
    		return 'http://mungy.mungy.mungy/';

    What you’ll see if the first time through the permalink for the post will be the default permalink and then for all the remaining posts the permalink will be ‘http://mungy.mungy.mungy/’.

    I THINK the solution is actually very simple, just move the following code from line 1908 to line 1892 (it worked for me on my test system):

    $GLOBALS['post'] = &$post;

    You can see the wayward sitemap at; just look for the second permalink. I’ll leave it that way for a day or two.

    Please let me know your thoughts. Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thanks for reporting this 🙂

    Yes, moving the line you wrote should fix the problem!

    Thanks Arnee!

    I noticed you released a new version today (v3.1.3); I assume you already had that release completed? Will you be making the fix in the next version? Thanks.

    -Mike Schinkel

    Hi Mike,

    yes, 3.1.3 was already released when I saw your posting. Since I don’t want to release a new version immediately again, I will include it with some other changes in the next one.



Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Google XML Sitemaps] Bug in Sitemap Generation when using ‘post_link’ hook’ is closed to new replies.