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_pagebut it is not working for me. All other arguments works but posts_per_page is not working. I have pagination on this page and posts_per_page works for all other pages of pagination but not for first (main) page.
So for testing purpose i create a blank template that just have one simple WordPress loop and not have pagination or any thing else that is displaying just post title and in this template i have limit on number of posts again but posts_per_page is not working even on this page.
I have tried disabling all plugins but there was no effect so i think this issue is with theme that is setting posts_per_page value dynamically.
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', 12 );
    return $query;
}

But nothing working for me. I have tried to display query content using var_dump($query->request)and in the query limit was 12 but on page i am still seeing 100+ posts. On WordPress settings page on theme settings page the posts limit is 12 but on front end this limit is not working. Here is the result of this query.

string(489) "SELECT SQL_CALC_FOUND_ROWS wp_mdw75t47kk_posts.ID FROM wp_mdw75t47kk_posts INNER JOIN wp_mdw75t47kk_postmeta ON ( wp_mdw75t47kk_posts.ID = wp_mdw75t47kk_postmeta.post_id ) WHERE 1=1 AND ( wp_mdw75t47kk_postmeta.meta_key = '_imwb_zonpress_post_ctr' ) AND wp_mdw75t47kk_posts.post_type="post" AND (wp_mdw75t47kk_posts.post_status="publish" OR wp_mdw75t47kk_posts.post_status="private") GROUP BY wp_mdw75t47kk_posts.ID ORDER BY wp_mdw75t47kk_postmeta.meta_value+0 DESC LIMIT 0, 12" 

I am also sharing url of this testing page if anybody wants to see this.
Test Page link
You will also be able to see this issue on main page as well. For me this is very strange issue because i have tried everything from google 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(
        'posts_per_page' => 12
);

$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; ?>

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.

5 Answers
5

Did you try this one?

<?php 
    $blogpost  =  new WP_Query(array(         
       'post_type'      => 'post',
       'posts_per_page' => 6
        ));
?>
<?php while($blogpost->have_posts()) : $blogpost->the_post(); ?>
// Writhe your Blog article Here.
<?php endwhile; ?>

Leave a Comment