I need to list all current WordPress Multisite Blogs apart from the one the user is on and the main blog. We have a 404 page where we'd like to recommend other blogs (physical places) apart from the blog the user is current on and the main blog.

Here is our structure:

Main Blog (places) Blog 1 (New York) Blog 2 (London) Blog 3 (Paris)

I can list all blogs but need to remove the main blog and the one the user is cirrently on from the list.


$bcount = get_blog_count();

global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE 
spam = '0' AND deleted = '0' and archived = '0' and public='1'"));
?><ul class="menu"><?php
foreach($blogs as $blog){
    $details = get_blog_details($blog->blog_id);
    if($details != false){
        $addr = $details->siteurl;
        $name = $details->blogname;
        if(!(($blog->blog_id == 1)&&($show_main != 1))){
            <li class="menu-item<?php if($counter == get_current_blog_id()){ echo ' current-menu-item';}?>">
                <a href="<?php echo $addr; ?>"><?php echo $name;?></a>
} ?>


1 Answer 1


This will list all blogs except the current one and the main one:

$blogs = get_sites(
    'number' => 99999999,
    'site__not_in' => array( get_current_blog_id(), 1 )

foreach( $blogs as $blog ) {
    $addr = $blog->siteurl;
    $name = $blog->blogname;
    echo $addr . " - " . $name . "<br>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.