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.

I want one particular category insert 12 post, but I only see some few posts.

Just like first time first 4 post and other time other post. What can I do?

Editor note:
I understand the issue is showing 4 posts in the first query, and the rest (8 from 12 in total) in the second query.

This is the code for the first time query:

<?php $the_query = new WP_Query('cat=6&order=ASC&showposts=4'); ?>
<?php  while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <div class="padding-10">
        <?php the_post_thumbnail(); ?>
        <div class="latestpost-dis">
            <div class="date"> <?php the_date(); ?> <span>BY</span> <?php the_author(); ?></div>
            <h4><?php the_title(); ?></h4>
            <p><?php the_excerpt(); ?></p>
            <p class="margin-top-20"><a href="#" class="btn btn-info">Read More</a></p>
        </div>

And this for the second time query:

<?php $the_query = new WP_Query('cat=6&order=ASC&showposts=-1,-2,-3,-4');?>
<?php  while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <div class="padding-10">
        <?php the_post_thumbnail(); ?>
        <div class="latestpost-dis">
            <div class="date"> <?php the_date(); ?> <span>BY</span> <?php the_author(); ?></div>
            <h4><?php the_title(); ?></h4>
            <p><?php the_excerpt(); ?></p>
            <p class="margin-top-20"><a href="#" class="btn btn-info">Read More</a></p>
        </div>
share|improve this question
4  
could you please reword your question correcting the grammar & explaining the problem you're having? –  Mridul Aggarwal Oct 31 '12 at 12:58
3  
have you read: codex.wordpress.org/Class_Reference/WP_Query –  Michael Oct 31 '12 at 13:40
3  
Please don't use bold for whole sentences. And please keep in mind that this is a Q/A site and not a forum, so proper Upper-/lowercase letters are appreciated. –  kaiser Oct 31 '12 at 14:08
add comment

3 Answers 3

You're not showing your entire code, so not all of these suggestions may be relevant:

  1. Use distinct, ideally descriptive, names for the variables that hold the different queries. Using the same variable, $my_query, can lead to unintended consequences.
  2. Be sure to close the first loop properly, with endwhile; endif;, before opening the second loop.
  3. Be sure to call wp_reset_postdata(); between the loops.
  4. If your intent is merely to offset the second loop by the posts returned in the first loop, use the offset parameter, rather than explicitly excluding post IDs.
  5. As @eric-holmes indicated, showposts is the wrong (and a deprecated) parameter to use, and should be replaced with posts_per_page.

Example:

$query4posts = new WP_Query( array(
    'cat' => 6,
    'order' => 'ASC',
    'posts_per_page' => 4
) );

$query8posts = new WP_Query( array(
    'cat' => 6,
    'order' => 'ASC',
    'posts_per_page' => 8,
    'offset' => 4
) ); 

// Output first loop of 4 posts
if ( $query4posts->have_posts() ) : while ( $query4posts->have_posts() ) : $query4posts->the_post();
    // Loop output
endwhile; endif;

wp_reset_postdata();

// Output second loop of 8 posts, offset
if ( $query8posts->have_posts() ) : while ( $query8posts->have_posts() ) : $query8posts->the_post();
    // Loop output
endwhile; endif;
share|improve this answer
    
To make it more efficient, you should query all 12 posts at once & then check the value of $query->current_post to come out of the first loop –  Mridul Aggarwal Oct 31 '12 at 13:48
    
Oh, there are surely more efficient approaches; this just answers the OP's question as-written, with respect to making two separate custom queries play nicely together. –  Chip Bennett Oct 31 '12 at 14:03
add comment

Your Query code is perfect. The problem is your arguments. showposts is deprecated, you should be using posts_per_page instead. It defines HOW MANY posts show up - hence why you are getting 4 posts in your first example. Your second example makes no sense, so that is probably why you are getting strange output.

share|improve this answer
add comment

First I would not use showposts= anymore as it will eventually be eliminated.

Have you tried using $the_query = new WP_Query( 'posts_per_page=3' ); instead?

Also double check how many posts you have set to display via your admin settings.

share|improve this answer
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.