Advertisement
Guest User

wp_query switch_to_blog

a guest
Mar 6th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.09 KB | None | 0 0
  1. <?php switch_to_blog(2); //boston offices ?>
  2. <?php
  3. // WP_Query arguments
  4. $args = array (
  5.     'post_type'              => 'office',
  6.     'pagination'             => false,
  7.     'posts_per_page'         => '-1',
  8.     'order'                  => 'ASC',
  9.     'orderby'                  => 'title',
  10. );
  11. // The Query
  12. $office2 = new WP_Query( $args ); ?>
  13. <?php if ($office2->have_posts()): ?>
  14. <?php while ($office2->have_posts()) : $office2->the_post(); ?>
  15.     <li class="text--center grid__item one-quarter s-one-whole xs-one-whole space all-cities all-neighborhoods all-types
  16.         <?php $getslugid = wp_get_post_terms( $post->ID, 'space-type' );
  17.             foreach( $getslugid as $thisslug ) {
  18.                 echo ' ' . $thisslug->slug . ' ';
  19.             }
  20.         ?>
  21.  
  22.         <?php $posts = get_field('neighborhood_name'); if( $posts ): ?>
  23.             <?php foreach( $posts as $p): // variable must be called $post (IMPORTANT) ?>
  24.                 <?php echo get_the_slug( $p->ID ); ?>
  25.             <?php endforeach; ?>
  26.         <?php endif; ?>
  27.  
  28.         <?php print strtolower(get_bloginfo('name')); ?>
  29.     ">
  30.         <?php
  31.             $count = 0;
  32.             if( have_rows('space_images') ): ?>
  33.             <?php while( have_rows('space_images') ): the_row();
  34.                 $count++;
  35.                 $image = get_sub_field('space_image');
  36.             ?>
  37.                 <?php if ($count == 1) { // grab the first image?>
  38.                     <a href="<?php the_field('space_neighborhood_parent'); ?>#<?php the_field('office_url_hash'); ?>">
  39.                         <img src="<?php echo $image; ?>">
  40.                     </a>
  41.                 <?php } else { // nothing -- we only want the first image to display?>
  42.                 <?php }  ?>
  43.             <?php endwhile; ?>
  44.         <?php endif; ?>
  45.         <hgroup>
  46.             <?php $posts = get_field('neighborhood_name'); if( $posts ): ?>
  47.                 <?php foreach( $posts as $p): // variable must be called $post (IMPORTANT) ?>
  48.                     <h6 class="hN"><?php echo get_the_title( $p->ID ); ?></h6>
  49.                 <?php endforeach; ?>
  50.             <?php endif; ?>
  51.             <h5 class="hN">
  52.                 <a href="<?php the_field('space_neighborhood_parent'); ?>#<?php the_field('office_url_hash'); ?>">
  53.                     <?php the_title(); ?>
  54.                 </a>
  55.             </h5>
  56.             <p class="hN"><?php the_field('office_address'); ?></p>
  57.             <p class="hN">
  58.                 <?php if( has_term( 'coworking-space', 'space-type', $post->ID ) ) { ?>
  59.                     <i class="fa fa-lg coworking-space"></i> Coworking Space
  60.                  <?php } ?>
  61.                  <?php if( has_term( 'shared-office-space', 'space-type', $post->ID ) ) { ?>
  62.                     <i class="fa fa-lg shared-office-space"></i> Shared Office Space
  63.                  <?php } ?>
  64.             </p>
  65.         </hgroup>  
  66.     </li><!--/.room-->
  67.  
  68. <?php endwhile; ?>
  69. <?php wp_reset_postdata(); ?>
  70. <?php endif;  // end loop?>
  71. <?php restore_current_blog(); ?>
  72.  
  73.  
  74.  
  75. <?php switch_to_blog(3); //beyond boston offices?>
  76. <?php
  77. // WP_Query arguments
  78. $args = array (
  79.     'post_type'              => 'office',
  80.     'pagination'             => false,
  81.     'posts_per_page'         => '-1',
  82.     'order'                  => 'ASC',
  83.     'orderby'                  => 'title',
  84. );
  85. // The Query
  86. $office3 = new WP_Query( $args ); ?>
  87. <?php if ($office3->have_posts()): ?>
  88. <?php while ($office3->have_posts()) : $office3->the_post(); ?>
  89.     <li class="text--center grid__item one-quarter s-one-whole xs-one-whole space all-cities all-neighborhoods all-types
  90.         <?php $getslugid = wp_get_post_terms( $post->ID, 'space-type' );
  91.             foreach( $getslugid as $thisslug ) {
  92.                 echo ' ' . $thisslug->slug . ' ';
  93.             }
  94.         ?>
  95.         <?php $posts = get_field('neighborhood_name'); if( $posts ): ?>
  96.             <?php foreach( $posts as $p): // variable must be called $post (IMPORTANT) ?>
  97.                 <?php echo get_the_slug( $p->ID ); ?>
  98.             <?php endforeach; ?>
  99.         <?php endif; ?>
  100.  
  101.         <?php print strtolower(get_bloginfo('name')); ?>
  102.     ">
  103.         <?php
  104.             $count = 0;
  105.             if( have_rows('space_images') ): ?>
  106.             <?php while( have_rows('space_images') ): the_row();
  107.                 $count++;
  108.                 $image = get_sub_field('space_image');
  109.             ?>
  110.                 <?php if ($count == 1) { // grab the first image?>
  111.                     <a href="<?php the_field('space_neighborhood_parent'); ?>#<?php the_field('office_url_hash'); ?>">
  112.                         <img src="<?php echo $image; ?>">
  113.                     </a>
  114.                 <?php } else { // nothing -- we only want the first image to display?>
  115.                 <?php }  ?>
  116.             <?php endwhile; ?>
  117.         <?php endif; ?>
  118.         <hgroup>
  119.             <?php $posts = get_field('neighborhood_name'); if( $posts ): ?>
  120.                 <?php foreach( $posts as $p): // variable must be called $post (IMPORTANT) ?>
  121.                     <h6 class="hN"><?php echo get_the_title( $p->ID ); ?></h6>
  122.                 <?php endforeach; ?>
  123.             <?php endif; ?>
  124.             <h5 class="hN">
  125.                 <a href="<?php the_field('space_neighborhood_parent'); ?>#<?php the_field('office_url_hash'); ?>">
  126.                     <?php the_title(); ?>
  127.                 </a>
  128.             </h5>
  129.             <p class="hN"><?php the_field('office_address'); ?></p>
  130.             <p class="hN">
  131.                 <?php if( has_term( 'coworking-space', 'space-type', $post->ID ) ) { ?>
  132.                     <i class="fa fa-lg coworking-space"></i> Coworking Space
  133.                  <?php } ?>
  134.                  <?php if( has_term( 'shared-office-space', 'space-type', $post->ID ) ) { ?>
  135.                     <i class="fa fa-lg shared-office-space"></i> Shared Office Space
  136.                  <?php } ?>
  137.             </p>
  138.         </hgroup>  
  139.     </li><!--/.room-->
  140.  
  141. <?php endwhile; ?>
  142. <?php wp_reset_postdata(); ?>
  143. <?php endif;  // end loop?>
  144. <?php restore_current_blog(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement