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.

I am struggling to get the get_last_updated() function to work on main blog.

I have a network site with about about 9 blogs on it.

I am simply trying to loop all my blogs and find do some querying from each blog. But I can't seem to get this simple get_last_updated() loop to work.

Can anyone please explain why this might not work?

Thanks in advance.

$events = get_last_updated();
foreach ($events as $event)
    {

        echo $event["blog_id"];

        switch_to_blog($event["blog_id"]);

        // do my stuff

        restore_current_blog();

}

Let me confirm. Is the get_last_updated() meant to return the latest added blogs.

Or is this function meant to check for latest post in within the blog and return the latest added blogs?

The codex does not really say what it does.

And it is confusing me very much as to why this is not working or not returning anything. It's like the function does not work - because if I do this...

$events = get_last_updated();

if ($events) { 

    foreach ($events as $event)
    {

        echo $event["blog_id"];

        switch_to_blog($event["blog_id"]);

        // do my stuff

        restore_current_blog();

    }

} else {

    echo 'help';

}

It just echo's help.

share|improve this question
    
do you get anything from <?php print_r(get_last_updated());?> –  birgire Apr 27 '13 at 9:33
    
nope - just... array() –  Joshc Apr 27 '13 at 9:55

2 Answers 2

You can try this instead of get_last_updated():

global $wpdb;
$blogs = $wpdb->get_results("SELECT blog_id, domain, path FROM {$wpdb->blogs} ORDER BY last_updated DESC" , ARRAY_A );
print_r($blogs);

just to see if it changes anything to skip the public, archived, mature, spam , site_id and deleted filters.

share|improve this answer
    
Thank your for you answer but I feel like an idiot. I did not have public ticked on any of my sites that is why get last update could not find it. Thank you –  Joshc Apr 28 '13 at 17:57
    
thanks for reporting back, cheers –  birgire Apr 28 '13 at 18:10
    
Your method is great though. I will use if for another time :-) –  Joshc Apr 28 '13 at 18:12

It was a very silly mistake I made.

I did not tick the public box in the network site settings on any of my site. This why get_last_updated(): was not returning anything.

share|improve this answer

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.