Title: WP_Sitemaps_Posts::get_url_list
Published: August 11, 2020
Last modified: February 24, 2026

---

# WP_Sitemaps_Posts::get_url_list( int $page_num, string $object_subtype ): array[]

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#wp--skip-link--target)

Gets a URL list for a post type sitemap.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#parameters)󠁿

 `$page_num`intrequired

Page of results.

`$object_subtype`stringoptional

Post type name. Default empty.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#return)󠁿

 array[] Array of URL information for a sitemap.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#source)󠁿

    ```php
    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.
    		 */
    		$sitemap_entry = apply_filters( 'wp_sitemaps_posts_show_on_front_entry', $sitemap_entry );
    		$url_list[]    = $sitemap_entry;
    	}

    	foreach ( $query->posts as $post ) {
    		$sitemap_entry = array(
    			'loc'     => get_permalink( $post ),
    			'lastmod' => wp_date( DATE_W3C, strtotime( $post->post_modified_gmt ) ),
    		);

    		/**
    		 * Filters the sitemap entry for an individual post.
    		 *
    		 * @since 5.5.0
    		 *
    		 * @param array   $sitemap_entry Sitemap entry for the post.
    		 * @param WP_Post $post          Post object.
    		 * @param string  $post_type     Name of the post_type.
    		 */
    		$sitemap_entry = apply_filters( 'wp_sitemaps_posts_entry', $sitemap_entry, $post, $post_type );
    		$url_list[]    = $sitemap_entry;
    	}

    	return $url_list;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php#L64)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php#L64-L169)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_sitemaps_posts_entry’, array $sitemap_entry, WP_Post $post, string $post_type )](https://developer.wordpress.org/reference/hooks/wp_sitemaps_posts_entry/)

Filters the sitemap entry for an individual post.

 [apply_filters( ‘wp_sitemaps_posts_pre_url_list’, array[]|null $url_list, string $post_type, int $page_num )](https://developer.wordpress.org/reference/hooks/wp_sitemaps_posts_pre_url_list/)

Filters the posts URL list before it is generated.

 [apply_filters( ‘wp_sitemaps_posts_show_on_front_entry’, array $sitemap_entry )](https://developer.wordpress.org/reference/hooks/wp_sitemaps_posts_show_on_front_entry/)

Filters the sitemap entry for the home page when the ‘show_on_front’ option equals‘
posts’.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Sitemaps_Posts::get_posts_query_args()](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_posts_query_args/)`wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php` |

Returns the query args for retrieving posts to list in the sitemap.

  | 
| [WP_Sitemaps_Posts::get_object_subtypes()](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_object_subtypes/)`wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php` |

Returns the public post types, which excludes nav_items and similar types.

  | 
| [wp_date()](https://developer.wordpress.org/reference/functions/wp_date/)`wp-includes/functions.php` |

Retrieves the date, in localized format.

  | 
| [wp_list_sort()](https://developer.wordpress.org/reference/functions/wp_list_sort/)`wp-includes/functions.php` |

Sorts an array of objects or arrays based on one or more orderby arguments.

  | 
| [WP_Query::__construct()](https://developer.wordpress.org/reference/classes/wp_query/__construct/)`wp-includes/class-wp-query.php` |

Constructor.

  | 
| [home_url()](https://developer.wordpress.org/reference/functions/home_url/)`wp-includes/link-template.php` |

Retrieves the URL for the current site where the front end is accessible.

  | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 4 more](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_sitemaps_posts/get_url_list/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Renamed `$post_type` to `$object_subtype` to match parent class for PHP 8 named parameter support. | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_sitemaps_posts%2Fget_url_list%2F)
before being able to contribute a note or feedback.