using pre_get_posts to exclude

try to implode $category with “,” as a glue. Mentioned code in each foreach run rewtites the cat variable of $query.

$query->set('cat', implode(',', $category));

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