[wp-hackers] Accessing custom post types and taxonomies across sites on a network
Bill Dennen
dennen at gmail.com
Mon Jan 24 20:14:46 UTC 2011
Hi,
We're using Multisite at a college -- each academic department has a
site on the network.
One one site, we've defined a custom post type (faculty_profile). One
that site, we also have a custom taxonomy defined (departments). As
you might guess, the custom post type is for faculty profiles (each
faculty member has one). Each profile is assigned to one or more
departments using the custom taxonomy departments.
One department sites, we'd like to be able to pull in a list of
faculty belonging to that particular department. For example, on the
Economics site, we'd like to display a list of all of the Economics
faculty.
To accomplish this, I thought I'd use switch_to_blog(), like this:
switch_to_blog(152);
$args = array (
'post_type' => 'faculty_profile',
'orderby' => 'meta_value',
'meta_key' => 'sortby',
'order' => 'ASC',
'posts_per_page' => -1,
);
query_posts( $args );
< do LOOP stuff >
wp_reset_query();
restore_current_blog();
This works fine. However, if I augment $args by passing it:
$args['departments'] = 'Economics';
I get nothing. It seems as though the taxonomy is not registered,
which I suppose makes some sense since the taxonomy on the profiles
site is registered in the theme that is unique to that site.
So, my question is this -- what is the right way to do this? Do I
temporarily define the taxonomy after switch_to_blog? or, is there a
better way to do this?
Thanks-
Bill
More information about the wp-hackers
mailing list