Sitemaps and custom post

Hi there, does this plugin works with custom post ?

Xml file just contains static pages.

  • aecnu
    • WP Unicorn

    Greetings guinnessboy,

    What do you mean custom posts types?

    The sitemaps can only be of pages and posts not of custom post types, Google will not even accept a sitemap with a URL that is not part of the primary domain.

    If I understand you correctly you want sitemaps created from custom posts types?

    Please advise.

    Cheers, Joe

  • aecnu
    • WP Unicorn

    Greetings guinnessboy,

    Not a problem on the English, just trying to figure out what we need done here :slight_smile:

    I am going to go ahead and see if I can get the lead developer in here with his invaluable insight to offer his advice/advise us if custom post types can indeed have site maps created from them.

    Though this may take a bit longer then a normal ticket, I will try to get him in here asap.

    Cheers, Joe

  • Vladislav
    • Dead Eye Dev

    Hello,

    At the moment, the plugin out of the box supports posts and pages only, but with the latest version (v1.1), it can easily be extended to support custom post types as well. To do this, you can hook up to “simple_sitemaps-generated_urlset” filter and append your custom post types to the generated urlset, similar to this:

    function my_sitemap_replacement ($content) {
    //return $content . '<empty>Nothing here</empty>';
    $totalposts = apply_filters('simple_sitemaps-totals_soft_limit', (defined('SIMPLE_SITEMAPS_POST_SOFT_LIMIT') ? SIMPLE_SITEMAPS_POST_SOFT_LIMIT : 50));
    $latestposts = $totalposts ? get_posts( 'post_type=MY_POST_TYPE&numberposts=' . $totalposts . '&orderby=date&order=DESC' ) : array();
    foreach ( $latestposts as $post ) {
    $content .= " <url>n";
    $content .= ' <loc>' . get_permalink( $post->ID ) . "</loc>n";
    $content .= ' <lastmod>' . mysql2date( 'Y-m-dTH:i:s', $post->post_modified_gmt ) . "+00:00</lastmod>n";
    $content .= ' <priority>' . number_format( 1, 1 ) . "</priority>n";
    $content .= " </url>n";
    }
    return $content;
    }
    add_filter('simple_sitemaps-generated_urlset', 'my_sitemap_replacement');

    Of course, you’ll want to substitute “MY_POST_TYPE” with your actual post type name.

  • Pierre-Yves
    • Site Builder, Child of Zeus

    Hi and thanks for your help,

    Where must i place this code ? In simple-sitemap.php

    Must it replace another part of code or must it be added.

    I have several custom post type post_1 post_2 aud others will be added.

    How does it works exactly ?

    Thanks.

  • 3SixtyEvolve
    • New Recruit

    Hello @guinnessboy

    Hope the code from Vladislav and additional input from Arun helped sorting out the issue.

    Note that since we haven’t heard back from you, I will go ahead and resolve this topic, but please don’t hesitate to reopen it if you still require additional feedback or support from our Support Team.

    Just select the ‘Mark as Not Resolved (re-open)’ box below the post area (otherwise we might miss your new post).

    Have a great day and all the best with your project!

    Gina

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.