• Resolved deflime

    (@deflime)


    I can only seem to exclude only one post type via the wpseo_sitemap_exclude_post_type filter. Is there a way to do multiple?

    Is there a way to repeat this or include more post types in a single call?

    function exclude_eu_posts( $excluded, $post_type ) {
    	return $post_type === 'post';
    }
    add_filter( 'wpseo_sitemap_exclude_post_type', 'exclude_eu_posts', 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello Deflime,

    Thanks for reaching out about excluding multiple post types from the sitemap. This should be possible, with something like the code below:

    function sitemap_exclude_post_type( $excluded, $post_type ) {
    	$excludedPostTypes = array("product", "post");
        if (in_array($post_type, $excludedPostTypes)) 
    	  return true;
    	return false;
    }
    add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );

    However, we recommend testing this on a staging site to see if it meets your expectations before using on a live site.

    Thread Starter deflime

    (@deflime)

    That works! Thank you so much Maybellyne.

    • This reply was modified 3 years, 3 months ago by deflime.

    I am having a problem right now. I also used this line of code

    function sitemap_exclude_post_type( $value, $post_type ) {
        if ( $post_type == 'listings' ) {
            return true;
        }
    }

    However, I tried to check the post type so that I would know if it’s working by including var_dump in it. As shown below:

    function sitemap_exclude_post_type( $value, $post_type ) {
        if ( $post_type == 'listings' ) {
            return true;
            var_dump($post_type);
        }
    }

    Suddenly, it shows list of post types so I knew it worked somehow. Once I removed the var_dump, it wouldn’t go out. Please help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude multiple post types from sitemap’ is closed to new replies.