In response to [[LINK href="http://www.wpquestions.com/question/show/id/65"]]my last question[[/LINK]], a bunch of people suggested that I use WPMU. I know nothing about WPMU. On my last question I emphasized how complicated the divisions of the site could get:
"The permissions get very complex - they want each person to be able to edit their own info, without being able to edit anyone else's info, and each division will have a person who is able to edit all of the information for that division, though they won't be able to edit the info of any other division."
But here's the thing, sometimes I need to be able to pull all the data together, to group data from multiple pages, to put it all into a table for sorting and sifting. So here is what I'd like to know about WPMU - can I get data from all parts of it and pull onto one page? Suppose I use WPMU to build the site, and each division gets its own blog (or section? What do you call it on WPMU?). When I need to list all of the corporate officers, from all the divisions, and get all their custom data, and all the custom fields, how do I do it?
Dan Davies answers:
WPMU is essentially a more feature-packed WordPress in that, you have the WPMU installation which works like a standard WP installation, but from that installation you're able to add new blogs at the click of a button. Each of these blogs acts as a WP installation, but it saves you the hassle of installing WP multiple times, updating each of them, and also gives you the ability to indeed share content and add multiple users to multiple blogs, and much more.
For example, if you wanted to query multiple posts that exist in different blogs, you could write something like the following (re-using code from another WPMU question):
<h3>Latest on this blog</h3>
<?php $current = new WP_Query('showposts=5'); ?>
<?php if($current->have_posts()) : ?><?php while($current->have_posts()) : $current->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<h3>Latest on blog 4</h3>
<?php switch_to_blog(4); ?>
<?php $blog4 = new WP_Query('showposts=5&cat=5'); ?>
<?php if($blog4->have_posts()) : ?><?php while($blog4->have_posts()) : $blog4->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
<?php restore_current_blog(); ?>
So what that is doing is showing 5 posts on the current blog (say the default WPMU blog), and then showing 5 posts from category 5 in blog ID 4.
In essence, you simply use the switch_to_blog(#) function to begin executing code that returns data relating to the blog ID you specify in switch_to_blog. After writing the switch_to_blog function, it performs as a standard WordPress installation/template would.
Tom Ransom answers:
The good news is that all the userdata and usermeta are stored in two tables that are linked.
In general, site-wide usermeta is stored as you'd find it in a wordpress site (metakey => metavalue). Blog specific usermeta are stored as wp_#_metakey => metavalue where (wp_) is the site prefix and the (#_) represents the blog number.
The system is flexible in that there is only one profile per user. A user can belong to one or more blogs and have different permissions for each. A blog owner can control who "belongs" to their blog or open the doors to all.
Max answers:
Like Darfuria said, you could use switch_to_blog() to apply your queries to each division.
It's a matter of learning the basic information retrieval functions of Wordpress (WP_Query, the Loop, getting meta data...).
If you think that this approach could bring to an excessive number of queries and performances are an issue, you are free to use "raw" MySql queries. It's not difficult if you use a tool to visualize the database schema.