これって関数とかグローバル変数とかで取得できなかったんだっけ?と思いつつ、
global $wpdb;
$modified = $wpdb->get_col( $wpdb->prepare( "SELECT MAX(post_modified_gmt) FROM $wpdb->posts WHERE post_status = %s AND (post_type = %s OR post_type = %s)", 'publish', 'post', 'news' ) );
echo date ( 'D, d M Y H:i:s +0900', strtotime ( $modified[0] ) );
RSS 2.0のlastBuildDateが目的だったので「Tue, 20 Sep 2016 07:25:37 +0900」みたいな形式に変換しています。
普通に「2016-09-20 16:25:37」でいいなら、
global $wpdb;
$modified = $wpdb->get_col( $wpdb->prepare( "SELECT MAX(post_modified) FROM $wpdb->posts WHERE post_status = %s AND (post_type = %s OR post_type = %s)", 'publish', 'post', 'news' ) );
echo $modified[0];
で大丈夫だし、
「2016年9月20日 16:25」とするなら
global $wpdb;
$modified = $wpdb->get_col( $wpdb->prepare( "SELECT MAX(post_modified) FROM $wpdb->posts WHERE post_status = %s AND (post_type = %s OR post_type = %s)", 'publish', 'post', 'news' ) );
echo date ( 'Y年n月j日 H:i', strtotime ( $modified[0] ) );
投稿にフックさせてoptionにタイムスタンプを保存するようにしておいた方がスマートかも。
function mytheme_post_publish( $post_id, $post ) {
if ( $post->post_type == 'post' || $post->post_type == 'news' )
update_option( 'posts_modified', time() );
}
add_action( 'publish_post', 'mytheme_post_publish', 10, 2 );
add_action( 'publish_news', 'mytheme_post_publish', 10, 2 );
function mytheme_change_post_status( $post ) {
if ( $post->post_type == 'post' || $post->post_type == 'news' ) {
global $wpdb;
$modified = $wpdb->get_col( $wpdb->prepare( "SELECT MAX(post_modified_gmt) FROM $wpdb->posts WHERE post_status = %s AND (post_type = %s OR post_type = %s)", 'publish', 'post', 'news' ) );
update_option( 'posts_modified', strtotime ( $modified[0] ) );
}
}
add_action( 'publish_to_pending', 'mytheme_change_post_status' );
add_action( 'publish_to_draft', 'mytheme_change_post_status' );
add_action( 'publish_to_private', 'mytheme_change_post_status' );
add_action( 'publish_to_trash', 'mytheme_change_post_status' );
echo date( 'D, d M Y H:i:s +0900', get_option( 'posts_modified' ) );