Skip to main content
4 of 9
deleted 1277 characters in body
wplearner
  • 489
  • 2
  • 9
  • 27

WordPress number of posts not changing with posts_per_page

I have thousands of posts that I am displaying on my home page. I want to control number of posts so for this I am using posts_per_page but it is not working for me.

I am also resetting the query before this loop using wp_reset_query(); and tried this code in functions.php as well.

add_action( 'pre_get_posts',  'set_posts_per_page'  );
function set_posts_per_page( $query ) {
    global $wp_the_query;
    $query->set( 'posts_per_page', 10 );
    return $query;
}

But nothing working for me. I am using covert store builder theme. Any suggestion will be much appreciated. Thank you!

Here is complete code for this loop.

wp_reset_query(); 
$args = Array('meta_key' => '_imwb_zonpress_post_ctr',
        'orderby' => 'meta_value_num',
        'order' => 'DESC',
        'posts_per_page' => 1,
        'paged' => get_query_var( 'page' ) ,
);
    
$query = new WP_Query( $args );

<?php while ( $query->have_posts() ) : $query->the_post(); ?> 
        

Then there is some code to display image, title and excerpt and I think this should not effect number of posts. After this these lines are given

<?php 
endwhile; ?>
wplearner
  • 489
  • 2
  • 9
  • 27