WordPress.org

Make WordPress Core

Ticket #12016: bmb_0006_t12016.patch

File bmb_0006_t12016.patch, 914 bytes (added by bumbu, 5 years ago)

the same with less code

  • wp-includes/general-template.php

     
    10681068        if ( !is_array($cache) ) 
    10691069                $cache = array(); 
    10701070 
    1071         // Quick check. If we have no posts at all, abort! 
    1072         if ( !$posts ) { 
     1071        // Quick check if at least one element in $posts is published post 
     1072        $flag=false; 
     1073        if ( $posts ) { 
     1074                foreach($posts as $post){ 
     1075                        if($post->post_type == 'post' && $post->post_status == 'publish'){ 
     1076                                $flag = true; 
     1077                                break; 
     1078                        } 
     1079                } 
     1080        } 
     1081        // If we have no posts at all or we don't know if we have or no published posts, abort! 
     1082        if( !$posts || $flag == false ) { 
    10731083                $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); 
    10741084                if ( !$gotsome ) { 
    10751085                        $cache[ $key ] = '';