WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Google XML Sitemaps] Bug in Sitemap Generation when using 'post_link' hook (4 posts)

  1. Mike Schinkel
    Member
    Posted 5 years ago #

    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;
    	else
    		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 http://pm-sherpa.com/sitemap.xml; 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.

  2. arnee
    Member
    Posted 5 years ago #

    Thanks for reporting this :)

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

  3. Mike Schinkel
    Member
    Posted 5 years ago #

    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

  4. arnee
    Member
    Posted 5 years ago #

    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.

    Thanks,

    Arne

Topic Closed

This topic has been closed to new replies.

About this Topic