• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Jetpack_Sitemap_Builder::post_to_sitemap_item() – Construct the sitemap url entry for a WP_Post.

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,
    );
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 27 November 2019

Primary Sidebar

Information

Function name: Jetpack_Sitemap_Builder::post_to_sitemap_item
Class ref: Jetpack_Sitemap_Builder
Plugin ref: Jetpack
Version: 9.2
Sourcefile: modules/sitemaps/sitemap-builder.php
File ref: modules/sitemaps/sitemap-builder.php
Deprecated?: No
API Letters: B,J,P,S,T

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites