• Resolved shemzone

    (@shemzone)


    Hi
    Is there a way to remove specific post categories from the sitemap
    I tried this but of course has no effect

    add_filter( 'slim_seo_sitemap_categories', function( $categories ) {
        $categories = array_diff( $categories, ['mycategory'] );
        return $categories;
    } );

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi @shemzone ,

    Please use this snippet:

    add_filter( 'slim_seo_taxonomy_query_args', function( $query_args ) {
        $query_args['exclude'] = [123]; // Your category IDs
    } );
    Thread Starter shemzone

    (@shemzone)

    Hi @rilwis and thank you for your snippet.
    What I understood from your snippet is “hide this category from the list of categories”, right?
    I think that I misspoke myself.
    What I meant:
    How to exclude all the posts from a given category (excepting using the “Hide from search results” checkbox of each post).

    Plugin Author Anh Tran

    (@rilwis)

    I got it. In that case, you need to modify query for posts sitemap. Please use this snippet:

    add_filter( 'slim_seo_sitemap_post_type_query_args', function( $query_args ) {
        $query_args['category__not_in'] = [123]; // Replace 123 with your cat IDs.
    } );
    Thread Starter shemzone

    (@shemzone)

    Hi @rilwis , thank you again but this time, with this filter, the sitemap is completely emptied, what ever the category id is in parameter 🙂

    Plugin Author Anh Tran

    (@rilwis)

    Hi @shemzone ,

    Sorry, I miss the return statement. Please try again with this snippet:

    add_filter( 'slim_seo_sitemap_post_type_query_args', function( $query_args ) {
        $query_args['category__not_in'] = [123]; // Replace 123 with your cat IDs.
        return $query_args;
    } );
    Thread Starter shemzone

    (@shemzone)

    Hi @rilwis
    Thank you, it solved the issue.
    Thanks a lot for your great support
    I can’t wait for you pro version 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to remove specific categories from the sitemap’ is closed to new replies.