posts_per_page doesnt work

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="https://wordpress.stackexchange.com/questions/70424/<?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="https://wordpress.stackexchange.com/questions/70424/<?php the_permalink(); ?>" title="<?php the_title(); ?> yazısını oku."><?php the_title(); ?></a></li>
<?php  endwhile;  wp_reset_query(); ?>

1 Answer
1

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 );

Leave a Comment