Skip to content

Instantly share code, notes, and snippets.

@data-enhanced
Created October 29, 2013 20:51
Show Gist options
  • Select an option

  • Save data-enhanced/7222372 to your computer and use it in GitHub Desktop.

Select an option

Save data-enhanced/7222372 to your computer and use it in GitHub Desktop.
Exclude a certain post from the loop.
From:
http://wordpress.org/support/topic/multiple-loops-if-first-post-in-loop-1-matches-first-post-in-loop-2-skip
Add this after the query:
$check = get_posts('cat=3&numberposts=1');
if ( $check[0]->ID == $post->ID ) continue;
Sample loop:
<?php $args = array( 'post_type' => 'post');
$loop = new WP_Query( $args ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post();
$check = get_posts('category_name=featured&numberposts=1');
if ($check[0]-> ID == $post->ID) continue; ?>
<a href="<?php the_permalink(); ?>" class="item-link isotope-item">
<article class="feed-item featured-story <?php the_field('isotope_size') ?>">
<div class="<?php the_field('isotope-view')?>">
<?php if ( has_post_thumbnail() ) { ?>
<?php the_post_thumbnail('full'); ?>
<?php } ?>
<h2><?php the_title(); ?></h2>
<div class="item-description <?php the_field('isotope-mask') ?>">
<p><?php the_excerpt(); ?></p>
<div class="byline">
"Author's Name "
<span class="btn">Read more...</span>
</div>
</div>
</div>
</article>
</a>
<?php endwhile ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment