Last active
August 29, 2015 14:07
-
-
Save craiggrella/708a0f462e92b55cd314 to your computer and use it in GitHub Desktop.
Custom query with staff list from advanced custom fields meta query
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
// Add Staff Picks below Staff Member | |
add_action( 'genesis_entry_content', 'os_add_recent_staff_picks' ); | |
function os_add_recent_staff_picks() { | |
// Custom Loop Calling Staff Picks from Author Currently being viewed | |
$staffname = get_the_title(); | |
// New Query for staff picks matching author name | |
$pick_args = array( | |
'posts_per_page' => 3, | |
'post_type' => 'staffpicks', | |
'meta_query' => array( | |
array( | |
'key' => 'staff_member', | |
'value' => get_the_ID(), | |
'compare' => '=' | |
) | |
) | |
); | |
$picks_query = new WP_Query ($pick_args); | |
?> | |
<div class="recent-staff-picks-area"> | |
<h3 class="recent-staff-picks-header">Recent Staff Picks</h3> | |
<?php if ( $picks_query->have_posts() ) : ?> | |
<?php $i = 0; // start counter for column classes?> | |
<div class="recent-staff-picks-list"> | |
<?php while ( $picks_query->have_posts() ) : | |
$picks_query->the_post(); | |
if ( ( $i % 3 ) == 0 ) { | |
// if categories divided by three has no remainder, it sets the class below to one-third and | |
// first column, otherwise it sets just one-third | |
echo '<div class="recent-staff-picks-item one-third first">'; | |
} else { | |
echo '<div class="recent-staff-picks-item one-third">'; | |
} | |
?> | |
<a class="pick-img" | |
href="<?php the_permalink(); ?>"><?php genesis_image( array( 'size' => 'gtpl-staff-pick-pic' ) ); ?></a> | |
<a class="pick-title" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
</div> | |
<?php | |
$i ++; | |
endwhile; | |
wp_reset_postdata(); ?> | |
</div> <!--end ul.recent-staff-picks-list--> | |
</div> <!--end .recent-staff-picks-area--> | |
<? | |
else : | |
echo '<p>Sorry, ' . $staffname . ' has no recent picks.</p>'; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment