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!
- The topic ‘Override posts-per-page setting in a custom request for posts.’ is closed to new replies.