• Resolved sroskylos

    (@sroskylo1)


    Am trying to exclude 2 specific product categories from default WordPress sitemap.

    Any help? Am stack!

    'wp_sitemaps_posts_query_args',
     function( $args, $post_type ) {
         if ( 'product_cat' !== $post_type ) {
             return $args;
         }
    
         $args['product_cat__not_in'] = isset( $args['product_cat__not_in'] ) ? $args['product_cat__not_in'] : array();
         $args['product_cat__not_in'][] = 2053;
         $args['product_cat__not_in'][] = 924;
         return $args;
     },
     10,
     2
    );
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Mirko P.

    (@rainfallnixfig)

    Hi @sroskylo1,

    Thanks for reaching out!

    Something is missing there, I think you should start with add_filter('wp_sitemaps_posts_query_args', function( $args, $post_type ).

    However, if it doesn’t work, since this is a fairly complex development topic I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter sroskylos

    (@sroskylo1)

    Yes @rainfallnixfig the code is

    add_filter(
      'wp_sitemaps_posts_query_args',
      function( $args, $post_type ) {
          if ( 'product_cat' !== $post_type ) {
              return $args;
          }
    
          $args['product_cat__not_in'] = isset( $args['product_cat__not_in'] ) ? $args['product_cat__not_in'] : array();
          $args['product_cat__not_in'][] = 2053;
          $args['product_cat__not_in'][] = 924;
          return $args;
      },
      10,
      2
    );
    

    But doesn’t exclude this categories from sitemap.

    • This reply was modified 2 years, 9 months ago by sroskylos.

    Hi @sroskylo1

    Thanks for sharing the code, but as recommended by Mirko, we encourage you to make use of the development related resources shared above, where you will get inputs from developers.

    Just to let you know that support for custom coding is beyond the scope of support we are able to provide in this forum. This particular forum is for questions that are related to the WooCommerce core features.

    Nevertheless, I’m going to leave this thread open for a bit to see if any developer is able to chime in to help you out here.

    Seems we’ve not had additional inputs on this thread. Thus, we encourage you to make use of the above resources.

    I’ll go ahead and mark the thread closed but please feel free to create a new thread if you have further questions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude Woocommerce Product Category From Sitemap’ is closed to new replies.