I am trying to use pre_get_posts to exclude categories from posting to the homepage. If I do it like so it works just fine
$query->set( 'cat', '-13,-7,-19,-12,-24,-21,-14');
that is hard coded in. I am building a custom admin that lists the categories in the admin menu. So now I want to use the id's that get selected in the admin menu. So I have assigned my id's to a variable and when I var_dump the variable, this is what I get
string(2) "13"
string(1) "7"
string(2) "19"
string(2) "12"
string(2) "24"
string(2) "21"
string(2) "14"
So all those are assigned to the variable $category and so I thought I could do this
$category = get_option( 'excludecats' );
foreach( $category as $exclude ){
$query->set( 'cat', '-'.$exclude );
}
when I view the source, I expect there to be 1987 lines of code but what I end up with is 3117 lines of code trying to use the foreach to exclude them. What am I doing wrong?