admin管理员组文章数量:1201413
I want to change the default screen option value for posts per page in the wp-admin area when listing posts in pending
mode. The default value is set to 20
.
Changing the value directly in the Screen Options tab will only affect the user, not all users like this answer suggests.
Any workable solution?
I want to change the default screen option value for posts per page in the wp-admin area when listing posts in pending
mode. The default value is set to 20
.
Changing the value directly in the Screen Options tab will only affect the user, not all users like this answer suggests.
Any workable solution?
Share Improve this question edited May 23, 2017 at 12:40 CommunityBot 1 asked Apr 18, 2014 at 17:06 Christine Cooper♦Christine Cooper 8,8877 gold badges60 silver badges93 bronze badges3 Answers
Reset to default 3Just an addiction to @KrzysiekDróżdż answer.
When viewing a specific post status the url query string variable 'post_status'
, is set to the name of the status, so you can use $_GET['post_status']
to narrow the effect of @KrzysiekDróżdż code only for pending posts:
function my_edit_per_page( $result, $option, $user ) {
$status = filter_input( INPUT_GET, 'post_status', FILTER_SANITIZE_STRING );
if ( $status === 'pending' && (int) $result < 1 )
return 20; // or whatever you want
}
add_filter( 'get_user_option_edit_post_per_page', 'my_edit_per_page', 10, 3 ); // for posts
It won't be very hard to do. Just add this to your functions.php or into your plugin:
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
This way you will change the default value. So if user changes it, it will remember user's choice.
The only problem is that this setting is common for entire post type editor. I'm afraid it won't be so easy to set it depending on post status (and not breaking anything).
I really don't understand why the choice to compare to < 1
from the other answers. Also, if $result
was zero (and it can't be), the function won't return anything.
I'm using it like this to force a minimum of 50 items per page in an array of pages. Add @gmazzap $status
code if needed.
$perpages = ['flamingo_inbound_messages', 'wpcf7_contact_forms', 'plugins', 'edit_post', 'edit_page'];
foreach($perpages as $option) {
add_filter( "get_user_option_{$option}_per_page", function ( $result, $option, $user ) {
if ( (int)$result < 50 ) $result = 50;
return $result;
}, 9999, 3 );
}
Sometimes, it's not obvious nor easy to find the page name used in the option. I've looked for them directly in the database. Just apply some number on a page and look for it as the meta_value
in wp_usermeta
:
本文标签: listChange default screen option value for posts per page
版权声明:本文标题:list - Change default screen option value for posts per page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738541887a2095655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论