How to change the number of posts shown in the WordPress admin area without hacking the core

use the hook!

use the hook!

It is easy to go in and hack the core WordPress files to change the hard-coded number, but I wanted to find a way to do it with a hook.  That way, I could one day change the number of posts shown using controls in the interface.

Though there is no filter provided for the number of posts displayed, I hit upon a method of doing this which I would like to share.  Perhaps someone will point out a better way, but for now this is making me happy

The trick is to hijack the query string just for the query that produces the table of posts.  Here’s what I did:

/**  * Extend the number of posts displayed in the Edit Posts  */ 
function dapl_query_string($query_string) {   
    global $pagenow;   
    if (is_admin() && $pagenow == 'edit.php') {
        $query_string = str_replace('posts_per_page=15', 'posts_per_page=100', $query_string); 
    }
    return $query_string; 
}  
add_filter('query_string', 'dapl_query_string');
Posted in Development, wordpress Tagged with: , , , , ,
4 comments on “How to change the number of posts shown in the WordPress admin area without hacking the core
  1. Shawn Parker says:

    You got me thinking – I think there’s at least 3 ways to skin this cat with hooks or filters… I might have to write something up on that now that you got my brain churning.

  2. That helped a lot … thanks a ton

  3. Andrew says:

    Hi Gregory – thank you for posting the solution to this one – please excuse my obvious ignorance, but – which file would I insert the code into?

    many thanks

    Andrew

  4. Andrew says:

    Big thank you to Gregory – I just successfully created my first plugin with your code – and of course understand a little more about the whole wordpress platform.

    Thank you for taking the time to follow up – I very much appreciate it.

    Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *

*