Skip to content

Instantly share code, notes, and snippets.

@mehrshaddarzi
Forked from freerangetech/page-faculty-staff.php
Created November 11, 2017 19:42
Show Gist options
  • Save mehrshaddarzi/b7d0c024c7b2a8e3152ccd38db51c084 to your computer and use it in GitHub Desktop.
Save mehrshaddarzi/b7d0c024c7b2a8e3152ccd38db51c084 to your computer and use it in GitHub Desktop.
Switch to Blog and WP_Query Example
<?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