Developer’s Corner: Useful MU Helper Functions for WPMU and BuddyPress

This week a new plugin for WPMU and BuddyPress quietly slipped into the repository with hardly a mention. The MU-Helpers plugin was written by Eric Marden to help make your life easier when developing solutions for WPMU and BuddyPress. Currently the plugin provides two functions that WPMU developers cannot live without: a function to return all posts from all blogs and one to return all comments on all blogs.

Get All Blog Posts

This function returns a sorted array of all posts across all blogs on the MU install using a quicksort algorithm to ensure that the list is in the order you specify. It uses the same Order By Paramaters as query_posts. The sort param is the column name in the database you want to sort on.

Usage:

1
get_all_blog_posts( $num_per_blog = 1, $orderby = 'date', $sort = 'post_date_gmt' )

Get All Blog Comments

This function returns a sorted array of all comments across all blogs on the MU install. It uses the same Order By Paramaters as get_comments.

Usage:

1
get_all_blog_comments( $num_per_blog = 1, $orderby = 'comment_date_gmt', $sort = 'comment_date_gmt' )

Please note that this plugin has not been tested with the new WordPress 3.0 Multi-Site Network. If you have a 3.0 MU install, feel free to test and let us know in the comments how it’s working.

MU-Helpers was created to be an evolving library of functions that will help to make life easier for developers. It’s still under active development. You can take a peek at its code and get involved in contributing to the project at github.com, where it’s currently being hosted. This is one plugin you’re going to want to follow as contributors add more useful functions that will save you time.

Featured Plugin - WordPress Membership Site Plugin

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
Find out more

Featured Plugin - WordPress Appointments Plugin

Take, set and manage appointments and client bookings without having to leave WordPress. Appointments+ makes it easy.
Find out more

Featured Plugin - WordPress Google Maps Plugin

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Featured Plugin - WordPress Newsletter Plugin

Now there's no need to pay for a third party service to sign up, manage and send beautiful email newsletters to your subscriber base - this plugin has got the lot.
Find out more

Featured Plugin - WordPress Q&A Site Plugin

It's now incredibly easy to start your own Q&A site using nothing more than WordPress - The Q&A plugin simply and brilliantly transforms any site, or page, into a perfect support or Q&A environment.
Find out more

Featured Plugin - WordPress Wiki Plugin

To get a wiki up and running you used to need to install Mediawiki and toil away for days configuring it... not any more! This plugin gives you *all* the functionality you want from a wiki, in WordPress!!!
Find out more

Featured Plugin - WordPress Ecommerce Shopping Cart Plugin

Out of all the WordPress ecommerce plugins available, MarketPress has got to be the winner - easy to configure, powerful functionality, multiple gateways and more. A simply brilliant plugin!
Find out more

Featured Plugin - WordPress Pop-Up Chat Plugin

No javascript required, no third part chat engine, just fully featured chat right in your own database on your own WP sites - couldn't be easier.
Find out more

Featured Plugin - WordPress Infinite SEO Plugin

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
Find out more

Comments (3)

  1. With a quick glance of the code, I would HIGHLY recommend against using those functions. Each will perform as many queries as you have blogs on your install for every page load.

    On a normal WPMU site with say 1000 blogs thats more than 1000 uncached queries on every page load. That would kill your site for a good while.

  2. Aaron thanks for the input. I was testing it out last night with very small WPMU sties (under 10 blogs). Maybe I should note this is not an option for large scale sites. Post/Commenet Indexer are a much safer way to go about this.

  3. Thanks for you input Aaron, but you are actually quite mistaken. The alternative to my approach would be to perform one big query to join all of the tables together – something that not only would be gnarly to write, and also quite inefficient to run. The series of simple selects performed here – with the sorting done later by the super-fast C-functions in PHP – is the ideal solution since these sql statements play into MySQL’s built in query cache (something that is almost always on by default, even on shared hosts) and is further enhanced by a more comprehensive WordPress caching strategy. I tested this out on a site with almost 600 blogs and it continued to run as fast when I had 6. More queries do not necessarily equal more overhead.

Participate