admin管理员组文章数量:1303389
I'm running a WP multisite-network on my professional website (). I'd like to play around with jQuery Mobile and deliver a different website and web experience to mobile users, so I created another site in this network on .
On the main (desktop) WP site, I created a "project" content type to sort my professional projects. On the mobile site I'll create, I'd like to be able to load these projects (from the desktop-WP db) instead of having to recreate all the projects to the mobile-WP site.
I already worked on something similar: I had to access WP content through a subdomain of the main WP site, using the 'require wp-load.php' technique, but I'm wondering if there is a built-in function in WP to do this in a cleaner way, as both sites are on the same network.
I'm running a WP multisite-network on my professional website (http://mydomain). I'd like to play around with jQuery Mobile and deliver a different website and web experience to mobile users, so I created another site in this network on http://m.mydomain.
On the main (desktop) WP site, I created a "project" content type to sort my professional projects. On the mobile site I'll create, I'd like to be able to load these projects (from the desktop-WP db) instead of having to recreate all the projects to the mobile-WP site.
I already worked on something similar: I had to access WP content through a subdomain of the main WP site, using the 'require wp-load.php' technique, but I'm wondering if there is a built-in function in WP to do this in a cleaner way, as both sites are on the same network.
Share Improve this question edited Oct 11, 2012 at 17:40 Paul T. 3191 gold badge7 silver badges19 bronze badges asked Sep 18, 2012 at 20:59 PierrePierre 811 silver badge3 bronze badges 01 Answer
Reset to default 3You can just use the function switch_to_blog before running the WP_Query on your post_type "projects".
Switch the current blog to a different blog. switch_to_blog(), is useful if you need to pull posts or other information from other blogs.
Sounds like this is what you want. So lets say you have your content on the main_site. Run this on the mobilesite:
// Get current blog_id
global $blog_id;
// Run this code if on mobilesite
// Change from blog_id 2 if another id
if( $blog_id == 2 ) {
// Switch to the main_site
switch_to_blog(1);
// Get from projects and all of the posts
$args = array(
'post_type' => 'projects',
'posts_per_page' => -1
);
// The Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
endwhile;
// Restore original Query & Post Data
wp_reset_query();
// Switch back to mobilesite
restore_current_blog();
}
本文标签: databaseWP Multisite load content from site X on site Y
版权声明:本文标题:database - WP Multisite: load content from site X on site Y 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741748528a2395682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论