[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 insitemap-core.phpwhere the global$postvariable is not set the first time through the loop. You callget_permalink($post->ID)but unfortunately it does not pass the$postvariable to the ‘post_link‘ filter, it only passes the default permalink string.You can recreate the problem by using this code in the
functions.phpfile 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.
The topic ‘[Plugin: Google XML Sitemaps] Bug in Sitemap Generation when using ‘post_link’ hook’ is closed to new replies.