[resolved] Override posts-per-page setting in a custom request for posts. (3 posts)

  1. maerk
    Posted 9 years ago #

    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:


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

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

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

    Thanks in advance!

  2. Silkjaer
    Posted 9 years ago #

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

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

  3. maerk
    Posted 9 years ago #

    You genius! It works!

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

Topic Closed

This topic has been closed to new replies.

About this Topic