My idea is to add an option to store the last modified time and change it whenever a post/page is updated.
We can use the save_post
filter to do this.
Basically we check if the creation date equals to the modified date, if yes then the post should be newly created, if not, we update the option with the new array of latest modified date and latest modified post ID.
add_action( 'save_post', 'save_last_modified_date', 10, 1 );
function save_last_modified_date( $post_id ) {
// If this is just a revision, do nothing.
if ( wp_is_post_revision( $post_id ) )
return;
$created_date = get_the_date( 'U', $post_id );
$modified_date = get_the_modified_date( 'U' );
$attr = get_option( 'lastModified', array() );
if ( $created_date !== $modified_date ) {
$attr['date'] = $modified_date;
$attr['post_id'] = $post_id;
update_option( 'lastModified', $attr );
}
}
Then you can get the last modified date across the whole site by calling:
$lastModifed = get_option( 'lastModified' );
if ( $lastModifed ) {
$date = $lastModifed['date];
$post_id = $lastModifed['post_id];
}