WordPress.org

Ready to get started?Download WordPress

Forums

posts_per_page not working (1 post)

  1. groupewibi
    Member
    Posted 1 year ago #

    Hi all,

    I turning around since few days now, and i really do not undertand.
    I want to limit the number of post i displaying, but it seem not working at all.

    My Query :

    $mesautresposts = new WP_Query(
    array(
    	'post_type' => 'post',
    	'posts_per_page'=> 10,
    	'order' => 'DESC',
    	'orderby' => 'date',
    	'post__not_in' => $do_not_duplicate,
    	'category__not_in' => $category_id,
    	'tax_query' => array(
          array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-aside, post-format-video' ),
            'operator' => 'NOT IN'
    	      )
        ),
    	)
    );
    if($mesautresposts->have_posts()): var_dump($mesautresposts->request);
    echo '<p>Number of post :'.$mesautresposts->found_posts.'</p>';
    
    while($mesautresposts->have_posts()): $mesautresposts->the_post(); $do_not_duplicate[] = $post->ID; ?>
    
    <p><?php the_title(); ?></p>
    
    <?php endwhile; endif; wp_reset_postdata(); ?>

    When i displaying the SQL query using 'var_dump($mesautresposts->request);' i have :

    SELECT SQL_CALC_FOUND_ROWS wp_2_posts.ID FROM wp_2_posts WHERE 1=1 AND wp_2_posts.ID NOT IN (5256,5262,5181,5119,5179,5124,4328,4316,4296,4287,5538,5159,5171,5156,4984) AND ( wp_2_posts.ID NOT IN ( SELECT object_id FROM wp_2_term_relationships WHERE term_taxonomy_id IN (193) ) ) AND wp_2_posts.post_type = 'post' AND (wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') AND ( wp_2_posts.ID NOT IN ( SELECT object_id FROM wp_2_term_relationships WHERE term_taxonomy_id IN (193) ) ) GROUP BY wp_2_posts.ID ORDER BY wp_2_posts.post_date DESC LIMIT 0, 10

    When i testing it directly in the database, all the results are ok, but when i displaying it in the page, it's not limiting the number of results.

    Rather than having 10 post displayed, i have 22 posts displayed, and the found_posts is displaying 132 Posts !

    I have look for filters and the pre_get_posts function in y template, and function.php, but nothing seem to modify the query.

    Any idea from where it can come from ?

Topic Closed

This topic has been closed to new replies.

About this Topic