I reckon this one is quick and easy… I think I’m just missing something very obvious. My inquiry is nearly identical to this stackoverflow post.
For non-admin users, the default filter for posts is ‘mine’ (the full filter list being: mine, all, published, drafts, pending, trash). So, when they click ‘posts’ for example, they are given a list of their own articles by default. I want it so the ‘all’ filter is the default.
Using the previously mentioned post, I have got this to work for posts flawlessly with this code:
add_action( 'load-edit.php', function()
{
global $typenow;
// Not our post type, bail out
if( 'post' !== $typenow )
return;
// Administrator users don't need this, bail out
if( current_user_can('add_users') )
return;
// Only the Mine tab fills this conditions, redirect
if( !isset( $_GET['post_status'] ) && !isset( $_GET['all_posts'] ) )
{
wp_redirect( admin_url('edit.php?all_posts=1') );
exit();
}
});
Great! Wonderful!
But I also want to apply this to a custom post type I’ve created. The post type slug is ‘community’, the plural label is ‘Blog Posts’ and the singular is ‘Blog Post’. This is the code I produced based on the above code:
add_action( 'load-edit-community.php', function()
{
global $typenow;
// Not our post type, bail out
if( 'community' !== $typenow )
return;
// Administrator users don't need this, bail out
if( current_user_can('add_users') )
return;
// Only the Mine tab fills this conditions, redirect
if( !isset( $_GET['blog_post_status'] ) && !isset( $_GET['all_blog_posts'] ) )
{
wp_redirect( admin_url('edit.php?post_type=community&all_posts=1') );
exit();
}
});
I tried a few combinations but still can’t seem to get it work (luckily they didn’t bring my site down). I tried to place this above and below the working code for the regular ‘post’ type, but it didn’t matter.
Would appreciate any help with this! Thanks.
EDIT: got it working now. seems i was trying to jump on a false hook. here is the working code:
add_action( 'load-edit.php', function()
{
global $typenow;
// Not our post type, bail out
if( 'community' !== $typenow )
return;
// Administrator users don't need this, bail out
if( current_user_can('add_users') )
return;
// Only the Mine tab fills this conditions, redirect
if( !isset( $_GET['post_status'] ) && !isset( $_GET['all_posts'] ) )
{
wp_redirect( admin_url('edit.php?post_type=community&all_posts=1') );
exit();
}
});
thanks @birgire!