Make WordPress Core

Ticket #14922: 14922.002.diff

File 14922.002.diff, 4.1 KB (added by aaroncampbell, 15 years ago)
  • wp-includes/post.php

     
    20742074
    20752075        $post = get_post($postid, $mode);
    20762076
    2077         if ( 
     2077        if (
    20782078                ( OBJECT == $mode && empty( $post->ID ) ) ||
    20792079                ( OBJECT != $mode && empty( $post['ID'] ) )
    20802080        )
     
    38923892 * @return string The date of the last post.
    38933893 */
    38943894function get_lastpostdate($timezone = 'server') {
    3895         global $cache_lastpostdate, $wpdb, $blog_id;
     3895        global $cache_lastpostdate, $wpdb, $blog_id, $wp_query;
    38963896        $add_seconds_server = date('Z');
    38973897        if ( !isset($cache_lastpostdate[$blog_id][$timezone]) ) {
     3898                $post_types = apply_filters( 'get_lastpostdate_post_types', $wp_query->query_vars['post_type'] );
     3899                array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
     3900                $post_types = "'" . implode( "', '", $post_types ) . "'";
    38983901                switch(strtolower($timezone)) {
    38993902                        case 'gmt':
    3900                                 $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
     3903                                $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_date_gmt DESC LIMIT 1");
    39013904                                break;
    39023905                        case 'blog':
    3903                                 $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
     3906                                $lastpostdate = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_date_gmt DESC LIMIT 1");
    39043907                                break;
    39053908                        case 'server':
    3906                                 $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date_gmt DESC LIMIT 1");
     3909                                $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_date_gmt DESC LIMIT 1");
    39073910                                break;
    39083911                }
    39093912                $cache_lastpostdate[$blog_id][$timezone] = $lastpostdate;
     
    39293932 * @return string The date the post was last modified.
    39303933 */
    39313934function get_lastpostmodified($timezone = 'server') {
    3932         global $wpdb;
     3935        global $wpdb, $wp_query;
    39333936
    39343937        $add_seconds_server = date('Z');
    39353938        $timezone = strtolower( $timezone );
     
    39383941        if ( $lastpostmodified )
    39393942                return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
    39403943
     3944        $post_types = apply_filters( 'get_lastpostmodified_post_types', $wp_query->query_vars['post_type'] );
     3945        array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
     3946        $post_types = "'" . implode( "', '", $post_types ) . "'";
    39413947        switch ( strtolower($timezone) ) {
    39423948                case 'gmt':
    3943                         $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3949                        $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_modified_gmt DESC LIMIT 1");
    39443950                        break;
    39453951                case 'blog':
    3946                         $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3952                        $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_modified_gmt DESC LIMIT 1");
    39473953                        break;
    39483954                case 'server':
    3949                         $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_modified_gmt DESC LIMIT 1");
     3955                        $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_modified_gmt DESC LIMIT 1");
    39503956                        break;
    39513957        }
    39523958