/**
* Get the modification date for the last modified post in the post type:
*
* @param array $post_types Post types to get the last modification date for.
*
* @return string
*/
function get_last_modified($post_types)
{
global $wpdb;
if (!is_array($post_types)) {
$post_types = array($post_types);
}
// We need to do this only once, as otherwise we'd be doing a query for each post type.
if (!is_array($this->post_type_dates)) {
$this->post_type_dates = array();
$query = "SELECT post_type, MAX(post_modified_gmt) AS date FROM {$wpdb->posts} WHERE post_status IN ('publish','inherit') AND post_type IN ('" . implode("','", get_post_types(array('public' => true))) . "') GROUP BY post_type ORDER BY post_modified_gmt DESC";
$results = $wpdb->get_results($query);
foreach ($results as $obj) {
$this->post_type_dates[$obj->post_type] = $obj->date;
}
unset($query, $results, $obj);
}
if (count($post_types) === 1 && isset($this->post_type_dates[$post_types[0]])) {
$result = $this->post_type_dates[$post_types[0]];
} else {
$result = null;
foreach ($post_types as $post_type) {
if (isset($this->post_type_dates[$post_type]) && strtotime($this->post_type_dates[$post_type]) > $result) {
$result = $this->post_type_dates[$post_type];
}
}
unset($post_type);
}
return $this->timezone->get_datetime_with_timezone($result);
}