-
-
Save mehrshaddarzi/b7d0c024c7b2a8e3152ccd38db51c084 to your computer and use it in GitHub Desktop.
Switch to Blog and WP_Query Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function smcm_pull_faculty_from_directory() { | |
//Get the slug of the calling site... array element [3] | |
$site_slug = explode ("/", get_site_url()); | |
// blog id of the directory | |
$blog_id = 7; | |
switch_to_blog( $blog_id ); | |
$args = array( | |
'post_type' => 'faculty_profile', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'dept_prog_tag', | |
'field' => 'slug', | |
'terms' => $site_slug[3] | |
) | |
) | |
); | |
$the_query = new WP_Query( $args ); | |
// The Loop | |
if ( $the_query->have_posts() ) { | |
while ( $the_query->have_posts() ) { | |
$the_query->the_post(); | |
the_post_thumbnail(array(100,100)); | |
echo '<p><a class="people-button" href="' . $permalink = get_permalink() . '">View Profile</a></p>'; | |
} | |
} else { | |
// no posts found | |
} | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
restore_current_blog(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment