diff --git a/wp-includes/template-functions-links.php b/wp-includes/template-functions-links.php index b63ebc4666..de7c99903f 100644 --- a/wp-includes/template-functions-links.php +++ b/wp-includes/template-functions-links.php @@ -504,14 +504,9 @@ function next_posts($max_page = 0) { // original by cfactor at cooltux.org function next_posts_link($label='Next Page »', $max_page=0) { global $paged, $result, $request, $posts_per_page, $wpdb; if (!$max_page) { - $nxt_request = $request; - //if the query includes a limit clause, call it again without that - //limit clause! - if ($pos = strpos(strtoupper($request), 'LIMIT')) { - $nxt_request = substr($request, 0, $pos); - } - $nxt_result = $wpdb->query($nxt_request); - $numposts = $wpdb->num_rows; + preg_match('#WHERE (.*) GROUP BY#', $request, $matches); + $where = $matches[1]; + $numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE $where"); $max_page = ceil($numposts / $posts_per_page); } if (!$paged) @@ -545,38 +540,12 @@ function previous_posts_link($label='« Previous Page') { } } -function posts_nav_link_old($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') { - global $request, $posts_per_page, $wpdb; - if (! is_single()) { - $show_what = get_query_var('what_to_show'); - - if (get_query_var('what_to_show') == 'posts') { - $nxt_request = $request; - if ($pos = strpos(strtoupper($request), 'LIMIT')) { - $nxt_request = substr($request, 0, $pos); - } - - $nxt_result = $wpdb->query($nxt_request); - $numposts = $wpdb->num_rows; - $max_page = ceil($numposts / $posts_per_page); - } else { - $max_page = 999999; - } - - if ($max_page > 1) { - previous_posts_link($prelabel); - echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep); - next_posts_link($nxtlabel, $max_page); - } - } -} - function posts_nav_link($sep=' — ', $prelabel='« Previous Page', $nxtlabel='Next Page »') { global $request, $posts_per_page, $wpdb; if (! is_single()) { if (get_query_var('what_to_show') == 'posts') { - preg_match('#WHERE 1=1 AND (.*)GROUP BY#', $request, $matches); + preg_match('#WHERE (.*) GROUP BY#', $request, $matches); $where = $matches[1]; $numposts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE $where"); $max_page = ceil($numposts / $posts_per_page);