Google XML Sitemaps
Doesn't support custom post types with dashes (1 post)

  1. Matthew Boynes
    Posted 3 years ago #

    I've just started using this plugin (4.0beta8) and I've noticed it relies heavily on dashes -- unfortunately, if your custom post type has dashes in it, they don't show up in XML files. This specifically happens in GoogleSitemapGeneratorStandardBuilder::BuildPosts() here:

    if(!$pts = strpos($params, "-")) return;
    $postType = substr($params, 0, $pts);

    If my post type is featured-projects then $postType becomes 'featured'.

    To fix this, I've changed this method from:

    if(!$pts = strpos($params, "-")) return;
    $postType = substr($params, 0, $pts);
    if(!in_array($postType, $gsg->GetActivePostTypes())) return;
    $params = substr($params, $pts + 1);
    global $wp_version;
    if(preg_match('/^([0-9]{4})\-([0-9]{2})$/', $params, $matches)) {
    	$year = $matches[1];
    	$month = $matches[2];
    	# ... lots of other code...


    if (!preg_match('/^(.*)-(\d{4})-(\d{2})$/', $params, $matches)) return;
    $postType = $matches[1];
    if(!in_array($postType, $gsg->GetActivePostTypes())) return;
    global $wp_version;
    $year = $matches[2];
    $month = $matches[3];
    # ... lots of other code...

    Here is a gist of the full file: https://gist.github.com/1775697

    Thus far, this has resolved this issue for me. However, since dashes are relied upon in other places, I would wage that there are other similar issues elsewhere in the plugin. Please let me know if I can be of any assistance in resolving any other issues.



Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Google XML Sitemaps
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by Matthew Boynes
  • This topic is not resolved
  • WordPress version: 3.3.1