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 have pagination on this page and posts_per_page
works for all other pages of pagination but not for first (main) page.
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' => 10,
'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; ?>
<div class="row-fluid">
<div class="span12">
<?php imwb_zonpress_page_numbers(); ?>
</div>
</div>
But as i mention i have tried this code in a blank template without pagination but still posts_per_page was not working. So i think an external hook setting this value. I have tried to find out this in theme files but was not successful. I know this is just because of this theme.