Actually
I think the issue is in the section:
$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
if ( !empty($cat_array) ) {
$excluded_categories = array_diff($excluded_categories, $cat_array);
$posts_in_ex_cats_sql = '';
}
When I use the parameter like this 1,2,3 and by pass the above section, everything works fine IN or NOT IN
Again, Just my thoughts, not a solution for production.