最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change default screen option value for media items per page (in media library)

programmeradmin0浏览0评论

I want to remove pagination by changing the default screen option value for posts per page, pages per page and media items per page, in the admin area, to 999. The default value is set to 20. I found the answer I need (I have pasted below from @KrzysiekDróżdż's answer in this question: Change default screen option value for posts per page) but am looking to also add a filter for the media library so it's consistent for all areas of the admin.

function my_edit_per_page( $result, $option, $user ) {
    if ( (int)$result < 1 )
        return 20; // or whatever you want
}
add_filter( 'get_user_option_edit_page_per_page', 'my_edit_per_page', 10, 3 );  // for pages
add_filter( 'get_user_option_edit_post_per_page', 'my_edit_per_page', 10, 3 );  // for posts

I've tried these, to no avail:

add_filter( 'get_user_option_edit_media_per_page', 'my_edit_per_page', 10, 3 );  // for media library
add_filter( 'get_user_option_edit_media_item_per_page', 'my_edit_per_page', 10, 3 );  // for media library
add_filter( 'get_user_option_edit_media_items_per_page', 'my_edit_per_page', 10, 3 );  // for media library

I want to remove pagination by changing the default screen option value for posts per page, pages per page and media items per page, in the admin area, to 999. The default value is set to 20. I found the answer I need (I have pasted below from @KrzysiekDróżdż's answer in this question: Change default screen option value for posts per page) but am looking to also add a filter for the media library so it's consistent for all areas of the admin.

function my_edit_per_page( $result, $option, $user ) {
    if ( (int)$result < 1 )
        return 20; // or whatever you want
}
add_filter( 'get_user_option_edit_page_per_page', 'my_edit_per_page', 10, 3 );  // for pages
add_filter( 'get_user_option_edit_post_per_page', 'my_edit_per_page', 10, 3 );  // for posts

I've tried these, to no avail:

add_filter( 'get_user_option_edit_media_per_page', 'my_edit_per_page', 10, 3 );  // for media library
add_filter( 'get_user_option_edit_media_item_per_page', 'my_edit_per_page', 10, 3 );  // for media library
add_filter( 'get_user_option_edit_media_items_per_page', 'my_edit_per_page', 10, 3 );  // for media library
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked May 7, 2014 at 11:51 codeviewcodeview 4551 gold badge13 silver badges25 bronze badges 1
  • Note that you need a return $result; after the return 20; to cover custom pagination values. Otherwise changing the pagination amount won't work. – guidod Commented Jul 4, 2017 at 21:26
Add a comment  | 

3 Answers 3

Reset to default 0

You need upload_per_page:

add_filter( 'get_user_option_edit_upload_per_page', 'my_edit_per_page', 10, 3 );

Since 2.9.0 version of wordpress the right way to change default screen option value for media items per page (in media library) is as follows:

function my_edit_media_per_page(){
    $media_per_page = 200; //or whatever you want
    return $media_per_page;
}

add_filter( 'upload_per_page', 'my_edit_media_per_page', 10, 3 );

Setting the value to 999 will screw up most wordpress hosting, I do not know whether it is PHP or Wordpress but I have tried 500 and it completely wrecks that feature. This is particularly true of images in media library, there seems to be a different setting for grid and list, so you still have access to list but if you select grid again you get a white screen of death. Now I have to go in the backend and try and figure out what field in what table holds the setting.

发布评论

评论列表(0)

  1. 暂无评论