Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-seopress/8237fab5df29485f8365bc454f75fc81 to your computer and use it in GitHub Desktop.
Save wp-seopress/8237fab5df29485f8365bc454f75fc81 to your computer and use it in GitHub Desktop.
Exclude out of stock WooCommerce products from the XML sitemap
function sp_sitemaps_single_query($args, $cpt_key) {
if ( $cpt_key == 'product' ) {
$args['tax_query'][] = array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => ['exclude-from-catalog', 'outofstock'],
'operator' => 'NOT IN',
);
}
return $args;
}
add_filter('seopress_sitemaps_single_query', 'sp_sitemaps_single_query', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment