0

I have a page template and on the page I have a loop such as:

query_posts('post_type=post&posts_per_page=5&paged='.get_query_var('paged')); 
if(have_posts()){
    while(have_posts()){
        the_post();
        the_title();
    }
}

The problem is that no posts are coming back when there should be about 5 or 6. Is there something wrong?

1 Answer 1

0

Firstly, use WP_query instead of query_posts:

Secondly, for (static) pages use the variable 'page' (not 'paged').

$my_query = new WP_query( 'post_type=post&posts_per_page=5&paged='  .get_query_var('page') );
if ( $my_query->have_posts() )  while( $my_query->have_posts() ) :
    $my_query->the_post();
    the_title();
endwhile;
2
  • That still didnt work, also: $my_query->the_title() is wrong. you only use $my_query up until the_post(). everything after like content, title, thumbnail and so on does not need it. - UPDate: it works
    – TheWebs
    Mar 5, 2013 at 20:54
  • I'm glad it helped. And sorry for the wrong title referencing. I guess, I was too busy doing copy/paste of $my_query->. ;)
    – tfrommen
    Mar 5, 2013 at 22:10

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.