Skip to content

Instantly share code, notes, and snippets.

@craiggrella
Created October 14, 2014 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craiggrella/5e504a2dfd7b81e24b88 to your computer and use it in GitHub Desktop.
Save craiggrella/5e504a2dfd7b81e24b88 to your computer and use it in GitHub Desktop.
// Custom Loop Calling Staff Picks from Author Currently being viewed
$picks = get_posts(array(
'posts_per_page' => 3,
'post_type' => 'staffpicks',
'meta_query' => array(
array(
'key' => 'author', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<?php if( $picks ): ?>
<ul>
<?php foreach( $picks as $pick ): ?>
<?php
$pick_item = get_field('author', $pick->ID);
?>
<li>
<a href="<?php echo get_permalink( $pick->ID ); ?>">
<?php echo get_the_title( $pick->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment