Exclude Bulk Posts

#62281
  • Resolved Jedi
    Rank Math free

    Hi. I have lots of posts (more than a hundred!) that I don’t want to include in the sitemap. So instead of putting each post ID in the ‘Exclude Posts’ field, what I did was just to put all posts under one category so then I only had to put the category ID in the ‘Exclude Terms’ field. This didn’t work though. So for instance I had the ‘pests’ category wherein all posts under this category I do not want included in the sitemap. After setting this up, I’m still seeing this on the sitemap:
    /pests/blog1
    /pests/blog2
    /pests/blog3
    /pests/blog4
    and so on…

    Did I understand how the ‘exclude posts and terms’ works correctly?

    Jedi C.

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can exclude posts from sitemap by setting them to noindex. You can make use of the following filter to noindex posts in your category.

    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
         global $post;
         // filter for only a specific post type
         if(get_post_type() == "your_post_type_name_here" && get_category() == "your_category"){
            $robots['index'] = "noindex";
            return $robots;
         }
    	return $robots;
    });

    Let us know how this goes.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Exclude Bulk Posts’ is closed to new replies.