$this->type, '@id' => Schema_AI_ID_Builder::archive( $taxonomy, $term_id ), 'url' => $url, 'name' => single_term_title( '', false ) ?: $term->name, 'isPartOf' => $this->get_website_reference(), ); $description = term_description( $term_id, $taxonomy ); if ( ! empty( $description ) ) { // term_description() returns raw HTML (may include shortcodes/tags // already rendered) — schema.org description wants plain text. $schema['description'] = wp_strip_all_tags( $description ); } $publisher = $this->get_publisher_reference(); if ( ! empty( $publisher ) ) { $schema['publisher'] = $publisher; } $item_list = $this->build_item_list( $term_id, $taxonomy ); if ( ! empty( $item_list['itemListElement'] ) ) { $schema['mainEntity'] = $item_list; } return $schema; } /** * Build the ItemList of posts in this term, most recent first. * * @param int $term_id WordPress term ID. * @param string $taxonomy Taxonomy slug. * @return array { '@type': 'ItemList', itemListElement: array } */ private function build_item_list( $term_id, $taxonomy ) { $query = new WP_Query( array( 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $term_id, ), ), 'post_status' => 'publish', 'posts_per_page' => self::MAX_LISTED_ITEMS, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); $items = array(); $position = 1; foreach ( $query->posts as $post ) { $items[] = array( '@type' => 'ListItem', 'position' => $position, 'url' => get_permalink( $post ), 'name' => get_the_title( $post ), ); ++$position; } wp_reset_postdata(); return array( '@type' => 'ItemList', 'itemListElement' => $items, ); } }