Best Practise: Linking to WPMU sites from other sites
Short answer but… get_blogaddress_by_name or get_blogaddress_by_id look to me like what you need. Both return the full blog URL.
Short answer but… get_blogaddress_by_name or get_blogaddress_by_id look to me like what you need. Both return the full blog URL.
If you use switch_to_blog, that use always also restore_current_blog. The restore_current_blog function undos the last call to switch_to_blog, but only by one step, the calls are not nestable, so always call restore_current_blog before calling switch_to_blog again.
Here’s how I’d attack your problem (in fact I think I’ve written code like this in the past, but I can’t find it at the moment): $blogs = array( 4, 1 ); $all_posts = array(); foreach( $blogs as $blog ) { switch_to_blog( $blog ); $args = array( ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, ‘order’ => … Read more
I figured out the answer, which seems to be an issue with WordPress. Using get_terms() to get terms from another site WORKS, BUT A TAXONOMY BY THE SAME NAME MUST BE PRESENT ON THE SUBSITE YOU’RE WORKING FROM. Below is my code (working): switch_to_blog(1); $taxonomy = array( ‘taxonomy_name’ ); $args = array( ‘orderby’ => ‘name’, … Read more
switch_to_blog(1); to switch to the root (primary) blog and pull post info. restore_current_blog(); to switch back.
If you want to work with it just like with WP_Query, you can use this construction. $query = new Network_Query( array( ‘blog_id’ => array( 1, get_current_blog_id() ), ‘posts_per_page’ => 5, ‘date_query’ => array( ‘after’ => date(‘Y-m-d’, strtotime(‘-1130 days’)) ), ‘meta_query’ => array( array( ‘key’ => ‘shows’, ‘value’ => $id, ‘compare’ => ‘LIKE’, ) ) ) … Read more
Check to see what you’re getting. The new WP_Query() isn’t working for some reason. Do a var_dumpon it. I suspect that you aren’t getting any results from the query, resulting in a Trying to get property of non-object when you try to access the methods.
Multisite wp_query & switch_to_blog issue
Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
Register submenu on network menu from the subsite