0

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.

  • 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
1

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.

  • 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
  • Your method is great though. I will use if for another time :-) – Joshc Apr 28 '13 at 18:12
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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