WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

OK, here's my prob. I have static homepage and a separate posts page on my wordpress site. I have defined the two in the admin panel. Now, I have also set the max number of posts to be displayed to 5(in settings> reading), but all the posts(10+) are still being displayed on the blog page.

I'm also displaying the latest 3 posts on the static homepage using a custom query. i.e

$wp_query = new WP_Query( array( 'posts_per_page' =>3));

<results loop code>

But this list also is displaying more than 3 posts.It seems wordpress is ignoring the posts_per_page limit I set whether I do it at the admin panel or through code. What the hell is going on? This is my 1st time using wordpress for developing a site. Is this a common problem for noobs?


I just stripped the static homepage bare and left a basic code block that simply fetches titles of the posts. More than 3 posts are still being returned. Here is the actual(and only) code currently in the homepage:

<div id="content">

  <?php $wp_query = new WP_Query( array( 'posts_per_page' => 3) );?>

  <?php if ( $wp_query->have_posts() ) : ?>
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
      <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
    <?php endwhile;?>
  <?php endif; ?>

share|improve this question
Based on the code you've included, you've done everything right, could you show some more of the code to help find where the error is? – mor7ifer Jan 16 '12 at 15:15
this doesn't necessarily have anything to do with your issue, but you should use some var other than $wp_query for your custom queries, that's the global var WordPress uses for the main loop, and you may get unpredictable results using it for other purposes. – Milo Jan 16 '12 at 17:10
up vote 1 down vote accepted

This could be caused by a theme or plugin overriding the WordPress settings. You could try enabling the TwentyEleven or TwentyTen theme, as well as disabling any plugins, to see if it works then.

If so, you could post which theme you are using (if it's prebuilt) or which plugins you had to disable to get it working - and we can see what can be done to remedy it.

share|improve this answer
Thanks. Disabled the stupid theme and it worked! I got it from devpress.com(news theme). It is hyped as an 'advanced' parent theme and users are warned not to 'touch' anything. I guess by 'advanced' they meant badly coded, as all i did was to add the post fetching code after it's fancy slideshow. – JCoder Jan 16 '12 at 18:33
 //just before calling your code add this and customize it as you like
 function hwl_home_pagesize( $query ) {
if ( is_admin() || ! $query->is_main_query() )

if ( is_home() ) {
    // Display only 1 post for the original blog archive
    $query->set( 'posts_per_page', 1 );

if ( is_post_type_archive( 'movie' ) ) {
    // Display 50 posts for a custom post type called 'movie'
    $query->set( 'posts_per_page', 50 );
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
share|improve this answer
Please add an explanation to your answer: why could that solve the problem? – toscho Feb 3 '14 at 22:50

I wanted to add my case to this list since it took me ages to debug, what happens is that i changed the number of posts an archive page displayed by hooking into the pre_get_post hook:

add_filter('pre_get_posts', 'number_of_posts_on_archive');
function number_of_posts_on_archive($query)
    if(is_post_type_archive(array('post_type1', 'post_type2')))
        $query->set('posts_per_page', 20);
    return $query;

And to fix the issue where it would include the post query for a completely different post type i added something like this to the if statement:

if( (is_post_type_archive(array('post_type1', 'post_type2'))) && ($query->get('post_type') !== 'post') )

The reason that i am posting it here is that this is the first result that came up on google search related to the search i did for it. So it might help somebody out who can't figure out for an hour... or two why the query just does not want to listen to you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.