切换到博客非常昂贵。。。下面是我使用的一些代码(我使用自己的寻呼机和查询变量)
function recent_mu_posts($howmany, $paged, $when, $until, $search) {
/* returns array of posts from all blogs in $blogs, newer than $when
* older than $until, containing $search
*/
global $options;
global $wp_query;
global $blogs;
global $wpdb;
global $table_prefix;
$blogPostTableNames = get_mu_tables();
if ( count( $blogPostTableNames ) > 0 ) :
$query = \'\'; $i = 0;
foreach ( $blogPostTableNames as $blogId => $tableName ) :
if ( $i > 0 ) :
$query.= \' UNION \';
endif;
$query.= " (SELECT ID, post_date, $blogId as `blog_id` FROM $tableName WHERE post_status = \'publish\' AND post_type = \'post\' AND post_date >= \'$when\' AND post_date <= \'$until\'";
if (isset($search)) $query.= " AND ( post_content COLLATE UTF8_GENERAL_CI LIKE \'%{$search}%\' OR post_title COLLATE UTF8_GENERAL_CI LIKE \'%{$search}% \')";
$query.=")";
$i++;
endforeach;
$query.= " ORDER BY post_date DESC ";
/* pagination */
$totalposts = $wpdb->get_results($query, OBJECT);
$ppp = intval( get_query_var( \'posts_per_page\' ) );
$on_page = $paged; #intval( get_query_var( \'paged\' ) );
if( $on_page == 0 ) $on_page = 1;
$offset = ( $on_page - 1 ) * $ppp;
//set global $wp_query object for pagination
$wp_query->found_posts = count($totalposts);
$wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp);
$wp_query->request = $query . " LIMIT $ppp OFFSET $offset";
//= " LIMIT $ppp OFFSET $offset";
$rows = $wpdb->get_results( $wp_query->request, OBJECT);
if ( $rows ) :
$posts = array();
$i=0;
global $post;
foreach ( $rows as $post ) :
$posts[$i] = get_blog_post( $post->blog_id, $post->ID );
$posts[$i]->blog_id = $post->blog_id;
$i++;
endforeach;
$wp_query->posts = $posts;
return $posts;
endif;
endif;
}