Ticket #739: 739.diff

File 739.diff, 2.8 KB (added by westi, 6 years ago)

First fix attempt

  • wp-includes/query.php

     
    868868                                $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', '; 
    869869                                $limits = 'LIMIT '.$pgstrt.$q['posts_per_page']; 
    870870                        } elseif ($q['what_to_show'] == 'days') { 
    871                                 $startrow = $q['posts_per_page'] * (intval($page)-1); 
    872                                 $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1"); 
    873                                 $endrow = $startrow + $q['posts_per_page'] - 1; 
    874                                 $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1"); 
     871//                              $startrow = $q['posts_per_page'] * (intval($page)-1); 
     872//                              $start_date = $wpdb->get_var("SELECT max(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $startrow,1"); 
     873//                              $endrow = $startrow + $q['posts_per_page'] - 1; 
     874//                              $end_date = $wpdb->get_var("SELECT min(post_date) FROM $wpdb->posts $join WHERE (1=1) $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date) ORDER BY post_date DESC LIMIT $endrow,1"); 
    875875 
     876                                $start_days = $q['posts_per_page'] * (intval($page)-1); 
     877                                $end_days = $start_days + $q['posts_per_page'] -1; 
    876878                                if ($page > 1) { 
    877                                         $where .= " AND post_date >= '$end_date' AND post_date <= '$start_date'"; 
     879                                        $where .= " AND post_date >= DATE_SUB(NOW(), INTERVAL '$end_days' DAY) AND post_date <= DATE_SUB(NOW(), INTERVAL '$start_days' DAY)";  
    878880                                } else { 
    879                                         $where .= " AND post_date >= '$end_date'"; 
     881                                        $where .= " AND post_date >= DATE_SUB(NOW(), INTERVAL '$end_days' DAY)"; 
    880882                                } 
    881883                        } 
    882884                } 
  • wp-includes/template-functions-links.php

     
    477477        } else { 
    478478                $posts = $wp_query->posts; 
    479479                preg_match('#WHERE\s(.*)\sGROUP BY#siU', $wp_query->request, $matches); 
    480                 $where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]); 
     480                //$where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]); 
     481                $where = preg_replace('/( AND )?post_date >= (.*?)( AND post_date <= (.*?))?/siU', '', $matches[1]); 
    481482                $num_days = $wpdb->query("SELECT DISTINCT post_date FROM $wpdb->posts WHERE $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date)"); 
    482483                return ceil($num_days / get_option('posts_per_page')); 
    483484        }