1

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

1 Answer 1

9

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 );
12
  • '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 Commented Oct 25, 2012 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. Commented Oct 25, 2012 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(); ?> Commented Oct 25, 2012 at 6:58
  • 1
    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 Commented Oct 25, 2012 at 7:02
  • 5
    SOLVED! The problem was I had some sticky posts. So the working query for me has 'posts_per_page'=>3 and 'ignore_sticky_posts'=>true. Commented Jan 19, 2016 at 17:14

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.