Advertisement
Guest User

Pulling multi-site post types in Wordpress

a guest
Aug 29th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <h2>News + Videos</h2>
  2. <?php
  3. $original_blog_id = get_current_blog_id(); // get current blog
  4.  
  5. $bids = array(1,2); // all the blog_id's to loop through EDIT
  6.  
  7. $catid_videos = 3; // EDIT
  8. $catid_news = 2; // EDIT
  9.  
  10. $cats = array(1 => $catid_videos, 2 => $catid_news); // setup a category for each blog EDIT
  11.  
  12. foreach($bids as $bid):
  13. switch_to_blog($bid); //switched to blog with blog_id $bid
  14.  
  15. // ... your code for each blog ...
  16. $posts = get_posts('&cat='.$cats[$bid].'&posts_per_page=10');
  17. echo "<ul> <strong>Items from blog_id=".$bid."</strong>";
  18. foreach($posts as $post){
  19. setup_postdata( $post );
  20.  
  21. echo "<li>";
  22. the_title();
  23. echo "</li>";
  24.  
  25. }
  26. echo "</ul><hr>";
  27.  
  28. endforeach ;
  29.  
  30. switch_to_blog( $original_blog_id ); //switched back to current blog
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement