Title: Exclude certain posts in bulk
Last modified: December 4, 2019

---

# Exclude certain posts in bulk

 *  Resolved [drimproove](https://wordpress.org/support/users/drimproove/)
 * (@drimproove)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/)
 * Hi,
 * I would like to know is does exist the possibility of bulk exclude from the sitemap.
   xml certain posts.
 * I mean, I have about 2000 posts I nedd to exclude from sitemap.xml. Do this thing
   one by one is impossible to me. Is there any possibility to add the posts IDs
   and exclude them from sitemap?
 * Best regards

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/#post-12203837)
 * Hi, no not possible yet. I’ve planned adding the exclude option to the bulk editor
   on the Posts list but can’t say when that will arrive…
 * What you could do in the mean time is use the existing `xmlsf_excluded` filter.
   Create a new new file **wp-content/mu-plugins/sitemap-exclude.php** in a plain
   text editor (like notepad or anything that does not add markup code!)
 *     ```
       <?php
   
       // filter exclude posts
       function drimproove_exclude_posts( $excluded, $post_id ) {
         // add your excluded post id's here
         $exclude_array = array( 1, 2, 3, 4 ); 
   
         if ( in_array( $post_id, $exclude_array ) ) $excluded = true;
   
         return $excluded;
       }
   
       add_filter('xmlsf_excluded','drimproove_exclude_posts',10,2);
       ```
   
 * Code is not tested so please prepare to delete the file again if your site goes
   blank 🙂
 *  Thread Starter [drimproove](https://wordpress.org/support/users/drimproove/)
 * (@drimproove)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/#post-12204328)
 * It worked perfectly! Thank you very much for your support and your quick answer!
 * Regards
 *  Thread Starter [drimproove](https://wordpress.org/support/users/drimproove/)
 * (@drimproove)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/#post-12207486)
 * Hi again,
 * So I tested that code with two post’s IDs and it worked perfectly but when I 
   tested the code with 2000 IDs (is the amount of posts that I need to exclude),
   some errors appeared.
 * Error #1
 *  Fatal error: Cannot redeclare drimproove_exclude_posts() (previously declared
   in /xxx/mu-plugins/sitemap-exclude.php:3) in /xxx/mu-plugins/sitemap-exclude_test.
   php on line 10
 * I solved this error deleting the test file I’ve created on the same directory
 * Error #2
 * Warning: Cannot modify header information – headers already sent by (output started
   at /xxx/mu-plugins/sitemap-exclude.php:17) in /xxx/plugins/sg-cachepress/core/
   Supercacher/Supercacher_Helper.php on line 68
 * So I deleted the plugin and no error messages are shown, but…now the sitemaps
   are shown with no format, like plain text.
 * I have made some test on Search Console, and it seems to be ok, so I’ll be monitoring
   it.
 * Thanks for sour support
 *  Plugin Author [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * (@ravanh)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/#post-12207667)
 * Hi, the first error is very logic if you create two plugin files with the same
   function (name), then this error will occur. Keep just one file 🙂
 * The second error will occur when there is something echoed or otherwise parsed
   as HTML in the PHP file. This will cause the server to start sending HTML with
   a header too soon, hence the “headers already sent” error later.
 * HTML output can be something that comes after `echo "...";` or even a simple 
   blank line in a PHP file that comes before the opening `<?php` or after the closing`?
   >` (does not need to be there) PHP tags.
 * Check the file you created and:
    1. make sure nothing is echoed there. 2. if 
   you a closing `?>` anywhere: if at the end of the file then simply remove it,
   if somewhere inside the function then paste your code in a reply… 3. make sure
   there is no blank line at the start of the file before the `<?php` tag
 * If the headers already sent error still occurs, please paste the code you have
   now in a reply (use the CODE button above the text field to start and and the
   code block with a back-tick sign) so I can see what else is wrong 🙂
    -  This reply was modified 6 years, 6 months ago by [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/).
    -  This reply was modified 6 years, 6 months ago by [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/).
    -  This reply was modified 6 years, 6 months ago by [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/).

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Exclude certain posts in bulk’ is closed to new replies.

 * ![](https://ps.w.org/xml-sitemap-feed/assets/icon-128x128.png?rev=1112143)
 * [XML Sitemap & Google News](https://wordpress.org/plugins/xml-sitemap-feed/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/xml-sitemap-feed/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/xml-sitemap-feed/)
 * [Active Topics](https://wordpress.org/support/plugin/xml-sitemap-feed/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/xml-sitemap-feed/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/xml-sitemap-feed/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Rolf Allard van Hagen](https://wordpress.org/support/users/ravanh/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/exclude-certain-posts-in-bulk/#post-12207667)
 * Status: resolved