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

Possible Duplicate:
How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling

I am using the following code on my archive.php template to list a few fields from a custom post type. It's an album review post type and this code pulls in the artist name, the album name and the album cover.

Is there any way to alter this code to tell wordpress to display a certain number of results?

The issue I have is that for all other archive pages the default (set to 10) is fine, but because I am only displaying a thumbnail and a name on the archive for reviews there's a lot of room to add more in.

share|improve this question

marked as duplicate by Chip Bennett, kaiser, toscho Aug 30 '12 at 23:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

You can hook into pre_get_posts and modify the query. Your hooked function will receive a WP_Query object as it's only argument. You can check to see if you're on a the correct post type archive and modify away.

Something like this:

add_action('pre_get_posts', 'wpse63675_pre_posts');
function wpse63675_pre_posts($q)

    $q->set('posts_per_page', 20); // or however many you want

You can drop the above in your functions.php file or a plugin. Use with caution.

I wrote a plugin that takes care of this for you. It does the above, but with a set of fields in the admin area.

share|improve this answer
+1 for the plugin and its code. Sidenote: Wouldn't it be better to hook the main file include process in a function hooked on plugins_loaded? Don't have to tell you why hooking stuff is a good idea ;) – kaiser Aug 30 '12 at 22:52
That's true. I tend not hook includes into anything, to be honest: I make assumptions about what classes and functions are available elsewhere in the plugin, and I don't want to check to see if they are there. Better idea (maybe?): if(apply_filters('plugin_enabled_somefeature', true)) { /* load the files for the feature */ } – chrisguitarguy Aug 30 '12 at 22:56
Hm. Interesting approach. I normally (with everyday stuff), just hook my bootstrap class into plugins_loaded. There all the includes happen and if needed, I hook into init, as its present during ajax, admin and public requests. Then the routing runs via all the conditional hooks (load-{$pagehook} and such) or via conditionals/query args for public requests. So far I've never thought about such an approach, but there're core filters (for e.g. the one on the gallery shortcode cb fn), that behave like switches. Will have to think about this one. If you want to discuss it, reach me via mail. – kaiser Aug 30 '12 at 23:35

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