To make an array, separate your values with commas rather than concatenate them with periods.
$upostcat= array (
$video,
$image,
$audio,
$writing,
$event
);
That part is pure PHP. However, I notice you want to use the category_name
“array”. If you are talking about WP_Query
, category_name
does not accept an array– really this is the only WordPress part of your question, by the way. What you actually want is a string with values separated by commas, like this from the Codex:
$query = new WP_Query( 'category_name=staff,news' );
For that you do need to concatenate. What you’ve done should mostly work except that you have a high probability of having a trailing comma. Imagine that one or more of the first four are set and the last one isn’t. There is an easier way.
if (isset($_POST['showvideo']) && ($_POST['showvideo'] == 'true')) {
$cats[]='user-video';
}
if (isset($_POST['showimage']) && ($_POST['showimage'] == 'true')) {
$cats[]='user-image';
}
if (isset($_POST['showaudio']) && ($_POST['showaudio'] == 'true')) {
$cats[]='user-audio';
}
if (isset($_POST['showwriting']) && ($_POST['showwriting'] == 'true')) {
$cats[]='user-writing';
}
if (isset($_POST['showevent']) && ($_POST['showevent'] == 'true')) {
$cats[]='user-event';
};
if (!empty($cats)) {
$upostcat = implode(',',$cats);
}