Hi Dr. Mike,
This CRON file is just 'latestposts.php', written by ColinFilmJournal.
I want to add site-wide category search on it:
// site wide Category Add by jeepmac
$sql = "select blog_id, path from wp_blogs where public=1 and spam=0 and blog_id>1";
$blogs = mysql_query($sql);
$sql = "";
$i = 0;
while ($blog = mysql_fetch_array($blogs)) {
if ($i == 0) {
$sql = $sql."select *, $blog[blog_id] as blog_id from wp_".$blog[blog_id]."_categories where category_nicename != 'uncategorized' and category_nicename != 'blogroll' and category_count !=0 ";
} else {
$sql = $sql."UNION select *, $blog[blog_id] as blog_id from wp_".$blog[blog_id]."_categories where category_nicename != 'uncategorized' and category_nicename != 'blogroll' and category_count !=0 ";
}
$i++;
}
$categories = mysql_query($sql);
mysql_query("delete from latest_categories");
mysql_query("delete from latest_post2cat");
while ($category = mysql_fetch_array($categories)) {
$sql = "select * from latest_categories where category_nicename='$category[category_nicename]'";
$temp = mysql_query($sql);
$temp = mysql_fetch_array($temp);
if ( $temp[category_count] ) {
$sql = "UPDATE latest_categories SET category_count =category_count+$category[category_count] WHERE category_nicename='$category[category_nicename]'";
mysql_query($sql);
} else {
$sql = "insert into latest_categories (cat_name, category_nicename, category_description, category_parent, category_count, link_count, posts_private, links_private) values ('$category[cat_name]', '$category[category_nicename]', '$category[category_description]', '$category[category_parent]', $category[category_count], $category[link_count], $category[posts_private], $category[links_private]);";
mysql_query($sql);
}
$sql = "select post_id from wp_".$category[blog_id]."_post2cat where category_id=$category[cat_ID]";
$posts = mysql_query($sql);
while ($post = mysql_fetch_array($posts)) {
$sql = "insert into latest_post2cat (blog_id, post_id, category_nicename) values ($category[blog_id], $post[post_id], '$category[category_nicename]')";
mysql_query($sql);
}
}
I create two tables for this function: latest_categories and latest_post2cat. The code can get wide site category successfully into ‘latest_categories'. But for every category, only one post_id is inserted to latest_post2cat.