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 am using a plugin called "Types" to generate custom post types for drink/food recipes. I want to show booth drink and food recipes on the same page. The posts are displaying fine, but for some reason, when you click "newer posts" or "older posts" it will bring you to a new page, but the new page will have the same posts as page 1. Anyone have any ideas? Thanks in advance!

Here's my loop:

<div class="postContainer">
    <ol class="news postList">
        <?php query_posts( array('post_type' => array( 'recipe', 'drink-recipe' ), 'cat' => array('12','8'), 'showposts' => 5 )); ?>
        <?php if( have_posts() ): ?>
        <?php while( have_posts() ): the_post(); ?>
        <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
        <li class="row">
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" style="background-image:url('<?php echo $image[0]; ?>')">
                <div class="seven offset-by-five">
                    <h3><?php the_title(); ?></h3>
                    <h4><?php the_time('F j, Y') ?></h4>
                    <?php echo the_excerpt(); ?>
                    <div href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="button">Read more</div>
                </div>
            </a>
        </li>
        <?php endwhile; ?>
    </ol>
</div>

<div id="pagenav">
    <span class="newer"><?php previous_posts_link(__('Newer Posts »','blog')) ?></span>
    <span class="older"><?php next_posts_link(__('« Older Posts','blog')) ?></span>
</div>   

<?php else: ?>

<div id="post404" class="noposts">

    <p><?php _e('None found.','404'); ?></p>

</div>

<?php endif; wp_reset_query(); ?>

<?php get_footer(); ?>
share|improve this question
1  
Have you looked over any of the "Related" questions on the right hand side of this page, or searched this website for a solution? What have you tried? –  Howdy_McGee Dec 5 '13 at 16:15
    
Of course you get the same posts, you are running the same query. Search the site for pre_get_posts –  s_ha_dum Dec 5 '13 at 16:21

1 Answer 1

up vote 0 down vote accepted

If you look here you'll see that pagination is a caveat of query_posts, and won't work without the paged variable

The right way to do

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

and then add:

'paged' => $paged

to your argument array within query_posts.

share|improve this answer
    
That worked great, thanks! –  APAD1 Dec 5 '13 at 16:28
1  
The right way to do it pretty much never involves query_posts at all. –  s_ha_dum Dec 5 '13 at 16:58

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.