there you go, i tested it in my current development and it works. it adds the post_type query parameter to all edit links, even on custom post types and also on the admin bar. this even works with preexisting query parameters and i also have other plugins currently running (f.ex. wpml).
function so370070_admin_url($url, $path)
{
if (strpos($path, "post.php") !== false) :
$post_type = get_post_type();
if ($post_type) :
$url = add_query_arg('post_type', $post_type, $url);
endif;
endif;
return $url;
}
add_filter('admin_url', 'so370070_admin_url', 10, 2);
and as solved by yourself, here is the links for attachments:
function so370070_register_post_type_args($args, $post_type)
{
if ($post_type == 'attachment') {
//NOTE: This "_edit_link" arg is noted for WordPress's internal use only
//in /wp-includes/post.php around line 84
//However, we are using a dveloper's filter to adjust it, so use accordingly
//that you understand it may need tweaked if WordPress itself makes changes
//Overall it should be generally safe... no issues so far :)
$args['_edit_link'] = add_query_arg('post_type', 'attachment', $args['_edit_link']);
}
return $args;
}
add_filter('register_post_type_args', 'so370070_register_post_type_args', 10, 2);