[wp-hackers] Accessing custom post types and taxonomies across sites on a network

Daniel Bachhuber d at danielbachhuber.com
Mon Jan 24 20:23:17 UTC 2011


Hey Bill,
Have you considered using a plugin like JSON API (http://db.ly/xc) to make the data accessible via API, and then just load the data with AJAX? We're doing this on our homepage to load posts from network blogs and it works well enough:

http://www.journalism.cuny.edu/

Our code is on GitHub if you'd like to peruse:

https://github.com/cunyjschool/CUNY-J-School/blob/master/js/main.js

Cheers,

Daniel

On 24 Jan 2011, at 3:14 PM, Bill Dennen wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

--
http://db.ly/info



More information about the wp-hackers mailing list