Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

is there a good and efficient way to fetch all WPMS blogs with archived set to true? Because there doesn't seem to be a function to get all blogs I have added the admin user to all blogs. Then I do a get_blogs_of_user(1, false). This fetch all blogs that are active, but I'm looking for an efficient way to fetch all blogs that is archived.

I guess I can do something complicated e.g. call get_blogs_of_user(1, true) then get_blogs_of_user(1, false), then find the difference and check if they have the archived bit set one by one, but is there some better way to do this?

Thanks.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can go directly to the database via $wpdb.

<?php
$wpdb->get_results( "SELECT * FROM $wpdb->blogs WHERE archived = 1" );

Or wrapped up in a function:

<?php
function wpse34731_get_archived_blogs()
{
    global $wpdb;
    if( empty( $wpdb ) ) return;

    $blogs = $wpdb->get_results( "SELECT * FROM $wpdb->blogs WHERE archived = 1" );
    return $blogs;
}
share|improve this answer
    
Thanks, of course. blush –  grm Nov 26 '11 at 16:08
    
Sadly it doesn't return the name of the blog. You wouldn't know if it's easy to get that as well or do I need to go into each seperate options table? If so, this is not very efficent afterall. –  grm Nov 28 '11 at 15:41
    
It's stored in a separate table. Try using get_blog_details to fetch the info. –  chrisguitarguy Nov 28 '11 at 16:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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