Show items by user_role

Here is an easy way to check if a user has a role. Note that I used your way of getting the WP_User, but there are others:

$user = new WP_User( $item->post_author );
// $user = get_userdata( get_current_user_id()); // another way to get logged in user
if ( !user_can($user->ID,'directory_4') ) {
    // show items, user does not have directory_4 role
}

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)