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.

Here is the my custom query ;

            <?php
                $Poz = new WP_Query(array(
                    'posts_per_page' => 3,
                    'orderby' => 'date',
                    'order' => 'DESC',
                    'no_found_rows' => true,
                    'update_post_term_cache' => false,
                    'update_post_meta_cache' => false,
                ));
            // The Query
            $the_query = new WP_Query( $Poz );

            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> yazısını oku."><?php the_title(); ?></a></li>
            <?php endwhile; wp_reset_postdata(); ?>

I start trying to minimize my queries. Found some articles about this. This method mean making just two queries.

You can check it here also.

The question is about posts_per_page arg. Why it doesnt work ? I think its about

'no_found_rows' => true,

this arg. That mean is no pagination for querie. But how we can limit post number ? or what we can use instead of posts per page in this query. Let talk about this.

-- Updated --

I Changed the querie method query_posts instead of new WP_Query;

<?php

# Cached Wordpress queries
# SE Disq : http://wordpress.stackexchange.com/questions/70424/posts-per-page-doesnt-work/70425

    $Poz = array(
    'posts_per_page' => 5, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'no_found_rows' => true,
    'update_post_term_cache' => false, 
    'update_post_meta_cache' => false, 
    );

    query_posts( $Poz ); while ( have_posts() ) : the_post(); ?>

    <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> yazısını oku."><?php the_title(); ?></a></li>
<?php  endwhile;  wp_reset_query(); ?>
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Yeah, use 'nopaging' => true

http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

$Poz = array( 
    'posts_per_page' => 3, 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'update_post_term_cache' => false, 
    'update_post_meta_cache' => false, 
    'nopaging' => true, 
); 
$the_query = new WP_Query( $Poz );
share|improve this answer
    
'nopaging' => true is the same ? is this making more query or not ? Also i add that line to but the results actually posts number display like main query –  Fatih Toprak Oct 25 '12 at 6:50
    
nopaging tells WordPress: look dude, I know you're paging by default, but stop this and just give me my X posts. So, less query, I suppose. –  Daniel Sachs Oct 25 '12 at 6:55
    
I confused but it doesnt work also. :/ <?php $Poz = new WP_Query(array( 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'nopaging' => true, )); $the_query = new WP_Query( $Poz ); // The Loop while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?> yazısını oku."><?php the_title(); ?></a></li> <?php endwhile; wp_reset_postdata(); ?> –  Fatih Toprak Oct 25 '12 at 6:58
    
Wait a sec. this is not the reason. I totally missed it. this should be: $Poz = array( 'posts_per_page' => 3, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'nopaging' => true, ); $the_query = new WP_Query( $Poz ); The $Poz should be args for the new WP_Query –  Daniel Sachs Oct 25 '12 at 7:02
    
try it please doesnt work. All posts came (: The query doesnt care with numbers. –  Fatih Toprak Oct 25 '12 at 7:06
show 5 more comments

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.