WordPress.org

Forums

[resolved] Default Screen Options Posts per Page > 20 for all users (8 posts)

  1. titush
    Member
    Posted 1 year ago #

    Hi there,

    I would need some help from the community. For a multi-author blog with authors that have little knowledge of WordPress, I would like to change the number of posts displayed in the admin back-end from the default (20) to 100.

    I would like to accomplish this through the functions.php but don't know where to start...

    This value should override the default 20. If a user chooses to manually set this value to anything different than 100, it should override that choice and set it to 100 regardless of user choice (I am actually hiding the screen options button for my contributors so this shouldn't be an issue anyway).

    Is this possible and could you point me into the right direction please?

    Thanks!

  2. titush
    Member
    Posted 1 year ago #

    By the way, I use AdMinimize to a accomplish a number of things but realize that is only playing around with CSS, not the core functions..

  3. shadez
    Member
    Posted 1 year ago #

    change to 100:

    function change_postsscreen_postcount(){
    global $per_page, $wp_query;
    $per_page = 500;
    $posts_per_page = 100;
    $wp_query->query('showposts='. $posts_per_page);
    }
    add_action('admin_head', 'change_postsscreen_postcount');

    this is to remove the option:

    add_action( 'admin_head', 'remove_wordpress_screenoptions' );
    function remove_wordpress_screenoptions() {
    echo '<style>.screen-options label { display: none; }</style>';
    echo '<style>.screen-options input { display: none; }</style>';
    }
  4. titush
    Member
    Posted 1 year ago #

    Awesome, thanks so much for your time! Works like a charm (I only tested the first code provided as I use adminimize to remove the screen options from certain user roles).

    You've bee anounced "hero fo the day" ,-)

    Cheers!

  5. titush
    Member
    Posted 1 year ago #

    Actually, I was a bit too early with my enthusiasm... I think this needs to be tweaked a little and I'd appreciate your help. What happens now is that any filter selection (i.e. list posts by category) is completely ignored...

    Any suggestion on how to fix this?
    Thanks so much for your time!

  6. shadez
    Member
    Posted 1 year ago #

    lolzz.. :)
    ok so then try only overloading the values like:

    function changescreenoptionagain(){
    $per_page = 100;
    $posts_per_page = 100;
    }
    add_action('admin_head', 'changescreenoptionagain');

    try if this works.
    also, try to understand what we are trying to do:
    in /wp-admin, screen.php file contains $per_page = 20; declaration within render_per_page_options() function. so ideally this is the fella we want to modify.
    $posts_per_page is declared in post.php file within /wp-admin again. and the function which contains this declaration is wp_edit_posts_query() - which is for the edit post page.
    so you can live with the first one alone too.
    and i guess we goofed up in the first code for calling the global wp_query.

  7. titush
    Member
    Posted 1 year ago #

    Hi shadez,

    thanks for coming up with the solution, needless to say it works... Indeed, this does help me learn how to use the functions and I'll soon try one of my own. The issue is always understanding where some information gets called, and the codex isn't always that helpful to a non-programmer ;-)

    Thanks for your time again, merry Xmas!

  8. shadez
    Member
    Posted 1 year ago #

    ok sorry to disappoint you again but that code is still buggy.
    i still couldnt figure out a better way to update those variable and feed to wp_query.

    anyways am adding a footnote here for all who wish to get their hands a bit dirty by tweaking their DB.
    basically when a user changes the posts value on screen, a new user meta key(edit_post_per_page) with value is inserted into 'usermeta' table, which is not present otherwise.
    so we could do an add/update of the key for all users, and give a new value for it, by adding this code to functions.php:

    function change_postscreen_allusers(){
    	$allblogusers = get_users( 'exclude=1' );
    	foreach ( $allblogusers as $user ) {
    		$key = 'edit_post_per_page';
    		$value = 100;
    		update_user_meta( $user->ID, $key , $value);
    	}
    }
    add_action('admin_head', 'change_postscreen_allusers');

    Do use after taking proper backups to be on the safer side.

Topic Closed

This topic has been closed to new replies.

About this Topic