/** * Get set of sitemap link data. * * @param string $type Sitemap type. * @param int $max_entries Entries per sitemap. * @param int $current_page Current page of the sitemap. * * @return array */ public function get_sitemap_links($type, $max_entries, $current_page) { global $wpdb; $links = array(); $taxonomy = get_taxonomy($type); if ($taxonomy === false || !$this->is_valid_taxonomy($taxonomy->name) || !$taxonomy->public) { return $links; } $steps = $max_entries; $offset = $current_page > 1 ? ($current_page - 1) * $max_entries : 0; /** This filter is documented in inc/sitemaps/class-taxonomy-sitemap-provider.php */ $hide_empty = apply_filters('wpseo_sitemap_exclude_empty_terms', true, $taxonomy); $terms = get_terms($taxonomy->name, array('hide_empty' => $hide_empty)); $terms = array_splice($terms, $offset, $steps); if (empty($terms)) { $terms = array(); } // Grab last modified date. $sql = "\n\t\t\tSELECT MAX(p.post_modified_gmt) AS lastmod\n\t\t\tFROM\t{$wpdb->posts} AS p\n\t\t\tINNER JOIN {$wpdb->term_relationships} AS term_rel\n\t\t\t\tON\t\tterm_rel.object_id = p.ID\n\t\t\tINNER JOIN {$wpdb->term_taxonomy} AS term_tax\n\t\t\t\tON\t\tterm_tax.term_taxonomy_id = term_rel.term_taxonomy_id\n\t\t\t\tAND\t\tterm_tax.taxonomy = %s\n\t\t\t\tAND\t\tterm_tax.term_id = %d\n\t\t\tWHERE\tp.post_status IN ('publish','inherit')\n\t\t\t\tAND\t\tp.post_password = ''\n\t\t"; foreach ($terms as $term) { $url = array(); $tax_noindex = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'noindex'); $tax_sitemap_inc = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'sitemap_include'); if ($tax_noindex === 'noindex' && $tax_sitemap_inc !== 'always') { continue; } if ($tax_sitemap_inc === 'never') { continue; } $url['loc'] = WPSEO_Taxonomy_Meta::get_term_meta($term, $term->taxonomy, 'canonical'); if (!is_string($url['loc']) || $url['loc'] === '') { $url['loc'] = get_term_link($term, $term->taxonomy); if ($this->options['trailingslash'] === true) { $url['loc'] = trailingslashit($url['loc']); } } if ($term->count > 10) { $url['pri'] = 0.6; } elseif ($term->count > 3) { $url['pri'] = 0.4; } else { $url['pri'] = 0.2; } $url['mod'] = $wpdb->get_var($wpdb->prepare($sql, $term->taxonomy, $term->term_id)); $url['chf'] = WPSEO_Sitemaps::filter_frequency($term->taxonomy . '_term', 'weekly', $url['loc']); $url['images'] = $this->image_parser->get_term_images($term); /** This filter is documented at inc/sitemaps/class-post-type-sitemap-provider.php */ $url = apply_filters('wpseo_sitemap_entry', $url, 'term', $term); if (!empty($url)) { $links[] = $url; } } return $links; }