Aha, well in that case you were totally on the right path!
Filtering by “author” takes a user ID, while filtering by “author_name” will take a text string. Try this:
add_action( 'pre_get_posts', 'filtre');
function filtre($query) {
if( !is_admin() ) {
$query->set('author', get_current_user_id() );
}
return $query;
}
Or alternatively, you could get the string name first and filter by “author_name” instead:
$user = wp_get_current_user();
$query->set('author_name', $user->data->user_nicename );