Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

change your query to:

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

http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters

share|improve this answer
    
Woop! Yes man you're a genius! Thank you very much. –  mattl May 13 '11 at 9:56
add comment

Your Answer

 
discard

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.