Return to Snippet

Revision: 36129
at November 18, 2010 12:01 by juanrossi


Initial Code
// Query for getting blogs
			$blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A );
					
			// put it in array	
	        foreach ( (array) $blogs as $details ) {$blog_list[ $details['blog_id'] ] = $details;}
	        unset( $blogs );
	        $blogs = $blog_list;
	        
	        // if is valid array
	        if (is_array( $blogs ) ){
	        		echo '<ul>';
	                $array= array();
	                // reorder
	                $array= array_slice( $blogs, 0, count( $blogs ) );
	                for($i=0;$i<count($array);$i++){
	                // get data for each id
	                $blog = get_blog_details( $array[$i]['blog_id'] );
	                // print it
	                echo '<li><a href="'.$blog->siteurl.'">'.$blog->blogname.'</a></li>';
	                }
	                echo '</ul>';
	        }

Initial URL
http://www.vulsai.com

Initial Description
This code is usefull for getting the list of Wordpress Sites from Multisite without sending each user id.

Initial Title
Get list of blogs from Wordpress Multisites / MU in a list

Initial Tags
php, wordpress

Initial Language
PHP