Okay I have a custom loop within the main loop of the page that shows 4 posts but obviously excludes the current main post. I'll show you:

<?php $my_query = new WP_Query( "cat=3&posts_per_page=4" );
    if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post();
        if($post->ID == $mainPost) continue; ?>
        <?php get_template_part('workThumb'); ?>
    <?php endwhile; endif; wp_reset_postdata(); ?>

However I want to show 4 posts in this loop but obviously if it contains the current post then it only shows 3. However if I increase the posts_per_page to 5 then on pages when it doesn't include the current post it shows 5 posts, which I don't want.

I hope this makes sense. Any ideas?

1 Answer 1


change your query to:

<?php $my_query = new WP_Query( array("cat" => 3, "posts_per_page" => 4, "post__not_in" => array($mainPost)));


  • Woop! Yes man you're a genius! Thank you very much.
    – mattl
    Commented May 13, 2011 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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