Ticket #966: 966.diff

File 966.diff, 1.2 KB (added by westi, 6 years ago)

Fix the query in _max_num_pages

  • wp-includes/template-functions-links.php

     
    475475                $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); 
    476476                return ceil($numposts / get_option('posts_per_page')); 
    477477        } else { 
    478                 $posts = $wp_query->posts; 
    479                 preg_match('#WHERE\s(.*)\sGROUP BY#siU', $wp_query->request, $matches); 
    480                 $where = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]); 
    481                 $num_days = $wpdb->query("SELECT DISTINCT post_date FROM $wpdb->posts WHERE $where GROUP BY year(post_date), month(post_date), dayofmonth(post_date)"); 
     478                preg_match('#FROM\s(.*)\sGROUP BY#siU', $wp_query->request, $matches); 
     479                $fromwhere = preg_replace('/( AND )?post_date >= (\'|\")(.*?)(\'|\")( AND post_date <= (\'\")(.*?)(\'\"))?/siU', '', $matches[1]); 
     480                $num_days = $wpdb->query("SELECT DISTINCT post_date FROM $fromwhere GROUP BY year(post_date), month(post_date), dayofmonth(post_date)"); 
    482481                return ceil($num_days / get_option('posts_per_page')); 
    483482        } 
    484483}