• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Yoast SEO a2z

Yoast SEO a2z

WordPress SEO a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / WPSEO_Sitemaps::get_last_modified_gmt() – Get the GMT modification date for the last modified post in the post type.

You appear to be a bot. Output may be restricted

Description

Get the GMT modification date for the last modified post in the post type.

Usage

$string|array|false = WPSEO_Sitemaps::get_last_modified_gmt( $post_types, $return_all );

Parameters

$post_types
( string|array ) required – Post type or array of types.
$return_all
( bool ) optional – Flag to return array of values.

Returns

string|array|false

Source

File name: wordpress-seo/inc/sitemaps/class-sitemaps.php
Lines:

1 to 52 of 52
  public static function get_last_modified_gmt( $post_types, $return_all = false ) {

    global $wpdb;

    static $post_type_dates = null;

    if ( ! is_array( $post_types ) ) {
      $post_types = [ $post_types ];
    }

    foreach ( $post_types as $post_type ) {
      if ( ! isset( $post_type_dates[ $post_type ] ) ) { // If we hadn't seen post type before. R.
        $post_type_dates = null;
        break;
      }
    }

    if ( is_null( $post_type_dates ) ) {

      $post_type_dates = [];
      $post_type_names = WPSEO_Post_Type::get_accessible_post_types();

      if ( ! empty( $post_type_names ) ) {
        $post_statuses = array_map( 'esc_sql', self::get_post_statuses() );

        $sql = "
					SELECT post_type, MAX(post_modified_gmt) AS date
					FROM $wpdb->posts
					WHERE post_status IN ('" . implode( "','", $post_statuses ) . "')
						AND post_type IN ('" . implode( "','", $post_type_names ) . "')
					GROUP BY post_type
					ORDER BY date DESC
				";

        foreach ( $wpdb->get_results( $sql ) as $obj ) {
          $post_type_dates[ $obj->post_type ] = $obj->date;
        }
      }
    }

    $dates = array_intersect_key( $post_type_dates, array_flip( $post_types ) );

    if ( count( $dates ) > 0 ) {
      if ( $return_all ) {
        return $dates;
      }

      return max( $dates );
    }

    return false;
  }
 

 View on GitHub View on Trac

Published: 27th November 2019 | Last updated: 8th June 2020

Primary Sidebar

Information

Function name: WPSEO_Sitemaps::get_last_modified_gmt
Class ref: WPSEO_Sitemaps
Plugin ref: Yoast SEO
Version: 15.4
Sourcefile: inc/sitemaps/class-sitemaps.php
File ref: inc/sitemaps/class-sitemaps.php
Deprecated?: No
API Letters: G,L,M,S,W

Footer

Yoast SEO a2z
Yoast SEO a2z
WordPress SEO 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:  wordpress-seo.wp-a2z.org
© Copyright Yoast SEO a2z 2017-2021. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites