61 responses to “Adding Custom Content Types to the Sitemap”

  1. jeff

    Hey – thanks so much for this fix! I know the original Google XML Sitemaps now has support for Custom Post Types in the beta version, but my client needed this now.

    Very cool of you to write and release this. Muchas Gracias, Amigo mio!

  2. OrT

    Still working like a charm, thanks a lot!

  3. Bora

    thanks! worked like a charm :)

  4. serge

    Hi,

    thanks for the code, you might be also interested in a function like this to exclude private post types automatically

    ( note gode is not tested yet) :

    function custom_exclude_non_public($post_types) {
    	$custom_post_types = get_post_types(array(
    		'_builtin' => false
    		),
    		'objects',
    		'and'
    	);
    	$keys = array_flip($post_types);
    	if(!is_null($keys)) {
    		foreach($custom_post_types as $custom_post_type) {
    			if($custom_post_type->publicly_queryable === false || $custom_post_type->exclude_from_search === true) {
    				$key = $keys[$custom_post_type->name];
    				unset($post_types[$key]);
    			}
    		}
    	}
    }
    add_filter('guar_sitemap_posttype_filter','custom_exclude_non_public',50,1);
    
  5. Matt Smith, modMACRO

    Doesn’t appear to work with WordPress 3.2.1 and XML Sitemap Generator 3.2.6 – Same results as without your plugin activated.

    Any thoughts?

  6. serge

    Hi, just tested the code here http://thesistut.com/

    it was buggy, here is the fixed version :

    function custom_exclude_non_public($post_types = array()) {
    	$custom_post_types = get_post_types(array(
    		'_builtin' => false
    		),
    		'objects',
    		'and'
    	);
    	$keys = array_flip($post_types);
    	if(!is_null($keys)) {
    		foreach($custom_post_types as $custom_post_type) {
    			if($custom_post_type->publicly_queryable === false || $custom_post_type->exclude_from_search === true) {
    				$key = $keys[$custom_post_type->name];
    				unset($post_types[$key]);
    			}
    		}
    	}
    	return $post_types;
    }
    add_filter('guar_sitemap_posttype_filter','custom_exclude_non_public',50,1);
    
  7. serge

    I have a question is there any way to apply same priority to custom post types as to posts?

  8. serge

    sorry, found that in the code

Leave a Reply