循环所有可用术语如何?如果术语有描述,请添加到object_ids
, 像这样的。
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\' ) {
// get the terms of the taxonomy
$terms = get_terms( \'post_tag\', [
\'hide_empty\' => false, // change to true if you want not empty terms
\'taxonomy\' => $taxonomy,
]);
// will contain all ids of terms that have description
$object_ids = [];
// loop terms
foreach ($terms as $term) {
// if term has description, add its id to our array
if (!empty($term->description)) $object_ids[] = $term->term_id;
}
// if we have ids (found terms with description) add it to the filter $args
if (!empty($object_ids)) $args[\'object_ids\'] = $object_ids;
}
return $args;
},
10,
2
);