Query categories that have a description
I want to query the categories and tags that have a description to make sure only those are listed in the sitemap. The description__like
argument used by get_terms() is the closest I've gotten to it.
// Clean sitemap
// https://wordpress.org/support/topic/remove-the-archive-pages-from-the-sitemap/
add_filter(
'wp_sitemaps_taxonomies_query_args',
function( $args, $taxonomy ) {
// Show in sitemap categories and topics that have a description
if ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) {
# First attempt
$args['description__like'] = '';
# Desperate second attempt
$args['meta_query'][] = array(
'key' = 'description',
'value' = array(''),
'compare' = 'NOT IN'
);
# Third attempt: seems to work
$args['description__like'] = ' ';
}
return $args;
},
10,
2
);
The third approach with the empty space seems to work, but I feel unsure about edge cases as I don't know why it works. Any clue about a more explicit way to do it or is this one OK?