You appear to be a bot. Output may be restricted
Description
Construct the sitemap url entry for a WP_Post.
Usage
$array = Jetpack_Sitemap_Builder::post_to_sitemap_item( $post );
Parameters
- $post
- ( WP_Post ) required – The post to be processed.
- $xml
- ( array ) required – An XML fragment representing the post URL.
- $last_modified
- ( string ) required – Date post was last modified.
Returns
array
Source
File name: jetpack/modules/sitemaps/sitemap-builder.php
Lines:
1 to 64 of 64
private function post_to_sitemap_item( $post ) { /** * Filter condition to allow skipping specific posts in sitemap. * * @module sitemaps * * @since 3.9.0 * * @param bool $skip Current boolean. False by default, so no post is skipped. * @param object $post Current post in the form of a $wpdb result object. Not WP_Post. */ if ( true === apply_filters( 'jetpack_sitemap_skip_post', false, $post ) ) { return array( 'xml' => null, 'last_modified' => null, ); } $url = esc_url( get_permalink( $post ) ); /* * Spec requires the URL to be <=2048 bytes. * In practice this constraint is unlikely to be violated. */ if ( 2048 < strlen( $url ) ) { $url = home_url() . '/?p=' . $post->ID; } $last_modified = $post->post_modified_gmt; // Check for more recent comments. // Note that 'Y-m-d h:i:s' strings sort lexicographically. if ( 0 < $post->comment_count ) { $last_modified = max( $last_modified, $this->librarian->query_latest_approved_comment_time_on_post( $post->ID ) ); } $item_array = array( 'url' => array( 'loc' => $url, 'lastmod' => jp_sitemap_datetime( $last_modified ), ), ); /** * Filter sitemap URL item before rendering it as XML. * * @module sitemaps * * @since 3.9.0 * * @param array $tree Associative array representing sitemap URL element. * @param int $post_id ID of the post being processed. */ $item_array = apply_filters( 'jetpack_sitemap_url', $item_array, $post->ID ); return array( 'xml' => $item_array, 'last_modified' => $last_modified, ); }