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 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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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;
share|improve this answer
    
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 '13 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->. ;) –  t f Mar 5 '13 at 22:10
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.