I have php set up in a template file to check a form and see if 1 or more of 5 categories is selected. Based on which one is selected, I want the custom query I'm using to change in that the array for "category_name" changes depending on what is selected.
I have gotten as far as defining the variables from the form but I can't figure out how to get the multiple variables to put themselves into an array. Here is an example of what I'm trying to do:
if (isset($_POST['showvideo']) && ($_POST['showvideo'] == 'true')) :
$video='user-video,';
endif;
if (isset($_POST['showimage']) && ($_POST['showimage'] == 'true')) :
$image='user-image,';
endif;
if (isset($_POST['showaudio']) && ($_POST['showaudio'] == 'true')) :
$audio='user-audio,';
endif;
if (isset($_POST['showwriting']) && ($_POST['showwriting'] == 'true')) :
$writing='user-writing,';
endif;
if (isset($_POST['showevent']) && ($_POST['showevent'] == 'true')) :
$event='user-event';
endif;
And then, I don't know how to get each of those values to put themselves into a correct array to use inside my custom query as the 'category_name' array.
This is obviously wrong:
$upostcat= array ($video . $image . $audio . $writing . $event);
Can someone help me with how to do this?
Updated WORKING code based on answer below (thanks!):
if (isset($_POST['showvideo']) && ($_POST['showvideo'] == 'true')) {
$cats[]='user-video';
} elseif (isset($_POST['showimage']) && ($_POST['showimage'] == 'true')) {
$cats[]='user-image';
} elseif (isset($_POST['showaudio']) && ($_POST['showaudio'] == 'true')) {
$cats[]='user-audio';
} elseif (isset($_POST['showwriting']) && ($_POST['showwriting'] == 'true')) {
$cats[]='user-writing';
} elseif (isset($_POST['showevent']) && ($_POST['showevent'] == 'true')) {
$cats[]='user-event';
};
if (!empty($cats) {
$upostcat = implode(',',$cats);
};