Reduce queries.
git-svn-id: http://svn.automattic.com/wordpress/trunk@727 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
572ba33802
commit
a8b5faacdc
|
@ -167,6 +167,7 @@ if ((empty($cat)) || ($cat == 'all') || ($cat == '0')) {
|
||||||
|
|
||||||
if ('' != $category_name) {
|
if ('' != $category_name) {
|
||||||
$category_name = preg_replace('|[^a-z0-9-/]|', '', $category_name);
|
$category_name = preg_replace('|[^a-z0-9-/]|', '', $category_name);
|
||||||
|
$tables = ", $tablepost2cat, $tablecategories";
|
||||||
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
|
$join = " LEFT JOIN $tablepost2cat ON ($tableposts.ID = $tablepost2cat.post_id) LEFT JOIN $tablecategories ON ($tablepost2cat.category_id = $tablecategories.cat_ID) ";
|
||||||
$whichcat = " AND (category_nicename = '$category_name') ";
|
$whichcat = " AND (category_nicename = '$category_name') ";
|
||||||
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
|
$cat = $wpdb->get_var("SELECT cat_ID FROM $tablecategories WHERE category_nicename = '$category_name'");
|
||||||
|
@ -319,6 +320,25 @@ if ($preview) {
|
||||||
// echo $request;
|
// echo $request;
|
||||||
$posts = $wpdb->get_results($request);
|
$posts = $wpdb->get_results($request);
|
||||||
|
|
||||||
|
|
||||||
|
// Get the categories for all the posts
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
$post_id_list[] = $post->ID;
|
||||||
|
}
|
||||||
|
$post_id_list = implode(',', $post_id_list);
|
||||||
|
|
||||||
|
$dogs = $wpdb->get_results("SELECT DISTINCT
|
||||||
|
ID, category_id, cat_name, category_nicename, category_description
|
||||||
|
FROM $tablecategories, $tablepost2cat, $tableposts
|
||||||
|
WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
|
||||||
|
|
||||||
|
foreach ($dogs as $catt) {
|
||||||
|
$category_cache[$catt->ID][] = $catt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do the same for comment numbers
|
||||||
|
|
||||||
|
|
||||||
if (1 == count($posts)) {
|
if (1 == count($posts)) {
|
||||||
if ($p || $name) {
|
if ($p || $name) {
|
||||||
$more = 1;
|
$more = 1;
|
||||||
|
|
|
@ -1332,7 +1332,10 @@ function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Ne
|
||||||
/***** Category tags *****/
|
/***** Category tags *****/
|
||||||
|
|
||||||
function get_the_category() {
|
function get_the_category() {
|
||||||
global $post, $tablecategories, $tablepost2cat, $wpdb;
|
global $post, $tablecategories, $tablepost2cat, $wpdb, $category_cache;
|
||||||
|
if ($category_cache[$post->ID]) {
|
||||||
|
return $category_cache[$post->ID];
|
||||||
|
} else {
|
||||||
$categories = $wpdb->get_results("
|
$categories = $wpdb->get_results("
|
||||||
SELECT category_id, cat_name, category_nicename, category_description
|
SELECT category_id, cat_name, category_nicename, category_description
|
||||||
FROM $tablecategories, $tablepost2cat
|
FROM $tablecategories, $tablepost2cat
|
||||||
|
@ -1340,6 +1343,7 @@ function get_the_category() {
|
||||||
");
|
");
|
||||||
|
|
||||||
return $categories;
|
return $categories;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_category_link($echo = false, $category_id, $category_nicename) {
|
function get_category_link($echo = false, $category_id, $category_nicename) {
|
||||||
|
|
Loading…
Reference in New Issue