WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Override posts-per-page setting in a custom request for posts.

[Resolved] Override posts-per-page setting in a custom request for posts.

  • Does anyone know if there’s a way to override the posts-per-page setting when requesting posts?

    In the options menu, I have it set so that there are 15 posts per page (i.e. 15 posts show up on the front page, and on the individual archive pages etc).

    What I’d like to be able to do is retrieve more posts than that, without having to change the setting? I’m working on a script which retrieves post titles for a given month, and I’d like to be able to retrieve all of them. At the moment it only shows 15.

    The script is at http://beingmrkenny.co.uk/blog/blogarchive.php to see how it works. To list the titles, the code I’m using is below:


    query_posts($query);

    if ( have_posts() ) : // begin if have posts

    $numberPosts = $wp_query->post_count;
    $numberOfPosts = 'numberposts=' . $numberPosts;
    $posts = get_posts($numberOfPosts);
    $date = "d-m-Y"; ?>
    <ol>
    <?php foreach ($posts as $post) : start_wp(); // begin Loop ?>
    <li>
    <strong><?php the_time($date); ?>:</strong>
    <a href="<?php echo get_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
    </li>
    <?php endforeach; endif; // end Loop ?>

    Where $query is either year=<year>&monthnum=<month> or just year=<year>

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("paged=$paged&showposts=15&".$query."");

    you need to do the paged part to check if your browsing paged 1 or 2 etc.. 🙂

    You genius! It works!

    I set showposts to 999, for those doing something similar.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Override posts-per-page setting in a custom request for posts.’ is closed to new replies.
Skip to toolbar