Skip to main content
Notice removed Draw attention by CommunityBot
Bounty Ended with no winning answer by CommunityBot
edited tags; edited title
Link
Michael Ecklund
  • 6.8k
  • 13
  • 68
  • 110

WordPress numberNumber of posts not changing withPosts Not Changing With posts_per_page

Tweeted twitter.com/StackWordPress/status/976510328723910656
edited body
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27

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. 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', 1012 );
    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 1012 but on page i am still seeing 100+ posts. On WordPress settings page on theme settings page the posts limit is 1012 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, 10"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' => 1012
);
    
$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.

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. 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', 10 );
    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 10 but on page i am still seeing 100+ posts. On WordPress settings page on theme settings page the posts limit is 10 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, 10" 

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' => 10
);
    
$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.

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. 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.

added 1349 characters in body
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27

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. 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.

I 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.

But nothing working for me. I amhave tried to display query content using covert store builder themevar_dump($query->request)and in the query limit was 10 but on page i am still seeing 100+ posts. Any suggestion will be much appreciatedOn WordPress settings page on theme settings page the posts limit is 10 but on front end this limit is not working. Thank you!

Here is complete code forthe result of this loopquery.

wp_reset_querystring(489); 
$args"SELECT =SQL_CALC_FOUND_ROWS Arraywp_mdw75t47kk_posts.ID FROM wp_mdw75t47kk_posts INNER JOIN wp_mdw75t47kk_postmeta ON ('meta_key' =>wp_mdw75t47kk_posts.ID '_imwb_zonpress_post_ctr',
= wp_mdw75t47kk_postmeta.post_id ) WHERE 1=1 AND ( wp_mdw75t47kk_postmeta.meta_key 'orderby'= =>'_imwb_zonpress_post_ctr' 'meta_value_num',
) AND wp_mdw75t47kk_posts.post_type = 'post' AND (wp_mdw75t47kk_posts.post_status = 'publish' 'order'OR =>wp_mdw75t47kk_posts.post_status 'DESC',
= 'private') GROUP BY wp_mdw75t47kk_posts.ID ORDER BY wp_mdw75t47kk_postmeta.meta_value+0 'posts_per_page'DESC =>LIMIT 100, 10" 

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(
     'paged' => get_query_var( 'page''posts_per_page' )=> ,10
);
    
$query = new WP_Query( $args );

<?php while ( $query->have_posts() ) : $query->the_post(); ?> 
        
<?php 
endwhile; ?>
<div class="row-fluid">
<div class="span12">
<?php imwb_zonpress_page_numbers(); ?>
</div>
</div>

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.

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(); ?> 
        
<?php 
endwhile; ?>
<div class="row-fluid">
<div class="span12">
<?php imwb_zonpress_page_numbers(); ?>
</div>
</div>

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. 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.

But nothing working for me. I have tried to display query content using var_dump($query->request)and in the query limit was 10 but on page i am still seeing 100+ posts. On WordPress settings page on theme settings page the posts limit is 10 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, 10" 

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' => 10
);
    
$query = new WP_Query( $args );

<?php while ( $query->have_posts() ) : $query->the_post(); ?> 
        
<?php 
endwhile; ?>
added 407 characters in body
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27
Loading
added 124 characters in body
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27
Loading
Notice added Draw attention by wplearner
Bounty Started worth 50 reputation by wplearner
deleted 1277 characters in body
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27
Loading
Fix formatting
Source Link
Dave Romsey
  • 17.9k
  • 11
  • 55
  • 70
Loading
Code added
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27
Loading
Source Link
wplearner
  • 489
  • 2
  • 9
  • 27
Loading