WP_Sitemaps_Posts::get_url_list( int $page_num, string $object_subtype = '' ): array[]
- Since
- 5.5.0, 5.9.0
- Source
wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php:64
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$page_numint- Page of results.
$object_subtypestringoptional- Post type name. Default empty.Default:
''
Return value
array[]- Array of URL information for a sitemap.
Performance profile
How much work a call to WP_Sitemaps_Posts::get_url_list() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 9–78
- Plugin surface
- 3 hooks
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 104.
Third-party callbacks on 'wp_sitemaps_posts_pre_url_list', 'wp_sitemaps_posts_show_on_front_entry', 'wp_sitemaps_posts_entry' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below WP_Sitemaps_Posts::get_url_list() - serializeserialisation
maybe_unserialize()one call below WP_Sitemaps_Posts::get_url_list() - querycontent query
get_post()one call below WP_Sitemaps_Posts::get_url_list()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Sitemaps_Posts::get_url_list() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($supported_types[$post_type]) | 9 | ->get_object_subtypes() |
isset($supported_types[$post_type]) && $url_list !== null | 18 | ->get_object_subtypes(), apply_filters() |
isset($supported_types[$post_type]) && $url_list === null | 34–37 | ->get_object_subtypes(), apply_filters(), ->get_posts_query_args() |
isset($supported_types[$post_type]) && $url_list === null && $post_type === "page" && $page_num === 1 | 41–42 | ->get_object_subtypes(), apply_filters(), ->get_posts_query_args(), get_option() |
isset($supported_types[$post_type]) && $url_list === null && $post_type === "page" && $page_num === 1 && empty($latest_posts) | 58–59 | ->get_object_subtypes(), apply_filters(), ->get_posts_query_args(), get_option(), home_url(), loc(), apply_filters() |
isset($supported_types[$post_type]) && $url_list === null && $post_type === "page" && $page_num === 1 && !empty($latest_posts) | 77–78 | ->get_object_subtypes(), apply_filters(), ->get_posts_query_args(), get_option(), home_url(), loc(), wp_list_sort(), strtotime(), wp_date(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 104 instructions, 9–78 executed per call, 8 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while WP_Sitemaps_Posts::get_url_list() runs, in this order:
- apply_filters( wp_sitemaps_posts_pre_url_list )filterline 87 (+23 into the body)
Filters the posts URL list before it is generated.
- apply_filters( wp_sitemaps_posts_show_on_front_entry )filterline 145 (+81 into the body)
Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'.
- apply_filters( wp_sitemaps_posts_entry )filterline 164 (+100 into the body)
Filters the sitemap entry for an individual post.
Uses · 9
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_option()Retrieves an option value based on an option name.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- wp_list_sort()Sorts an array of objects or arrays based on one or more orderby arguments.
- wp_date()Retrieves the date, in localized format.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- WP_Sitemaps_Posts::get_object_subtypes()Returns the public post types, which excludes nav_items and similar types.
- WP_Sitemaps_Posts::get_posts_query_args()Returns the query args for retrieving posts to list in the sitemap.
- WP_Query::__construct()Constructor.
Source code
public function get_url_list( $page_num, $object_subtype = '' ) { // Restores the more descriptive, specific name for use within this method. $post_type = $object_subtype; // Bail early if the queried post type is not supported. $supported_types = $this->get_object_subtypes(); if ( ! isset( $supported_types[ $post_type ] ) ) { return array(); } /** * Filters the posts URL list before it is generated. * * Returning a non-null value will effectively short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param array[]|null $url_list The URL list. Default null. * @param string $post_type Post type name. * @param int $page_num Page of results. */ $url_list = apply_filters( 'wp_sitemaps_posts_pre_url_list', null, $post_type, $page_num ); if ( null !== $url_list ) { return $url_list; } $args = $this->get_posts_query_args( $post_type ); $args['paged'] = $page_num; $query = new WP_Query( $args ); $url_list = array(); /* * Add a URL for the homepage in the pages sitemap. * Shows only on the first page if the reading settings are set to display latest posts. */ if ( 'page' === $post_type && 1 === $page_num && 'posts' === get_option( 'show_on_front' ) ) { // Extract the data needed for home URL to add to the array. $sitemap_entry = array( 'loc' => home_url( '/' ), ); /* * Get the most recent posts displayed on the homepage, * and then sort them by their modified date to find * the date the homepage was approximately last updated. */ $latest_posts = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); if ( ! empty( $latest_posts->posts ) ) { $posts = wp_list_sort( $latest_posts->posts, 'post_modified_gmt', 'DESC' ); $sitemap_entry['lastmod'] = wp_date( DATE_W3C, strtotime( $posts[0]->post_modified_gmt ) ); } /** * Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the home page.Changelog
Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$post_type to $object_subtype to match parent class for PHP 8 named parameter support.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.