WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am writing a custom multiple loop to be used on a custom category template page. The loop should put one post that is checked as featured in admin, in a separate div, and continue the loop displaying all posts from the category except the featured.

Similar to the example provided on the codex page except I don't want to create a separate category for the featured post.

I am using Advanced Custom Fields plugin for the check box that sets posts as featured.

I have the following issue with my code: if ($post->ID == $do_not_duplicate) continue; prevents rest of the loop to be executed. The code below just pulls the latest featured post.

Here is my function:

function featured() {
$featured = new WP_Query(array(
'meta_query' => array(
        'key' => 'featured',
        'value' => '"top"',
        'compare' => 'LIKE'
'posts_per_page' => 1

while ( $featured->have_posts() ) : $featured -> the_post(); 
$do_not_duplicate = $post->ID; ?>
<div id="featured">
    //featured post
</div><!-- end #featured -->
if(have_posts()) : while (have_posts()) : the_post();
if ($post->ID == $do_not_duplicate) continue;
<div class="container">
// normal posts
</div><!-- .charities-container -->
share|improve this question

Replace $do_not_duplicate = $post->ID; with $do_not_duplicate = get_the_ID();.

After the first loop (the featured) call wp_reset_postdata();


</div><!-- end #featured -->


if( have_posts() ) : while ( have_posts() ) : the_post(); 

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.