I am using channel form to allow users to add a new entry. I need to output a category to allow then to select multiple categories and sub categories. The following code works but it does not order the sub cats below the parent Category:

<select name="category[]" size="100" multiple="multiple" id="multiSelect">
{exp:query sql="SELECT cat_name, cat_id FROM exp_categories WHERE group_id='3'"}
<option value='{cat_id}'>{cat_name}</option>

I would like to see the categories listing as:

Parent 1
 child 1.1
 child 1.2
Parent 2
 Child 2.1
 Child 2.2

1 Answer 1


The docs provide a couple of syntax options:

        <label for="categories">Categories</label>
        <select name="category[]" id="categories" size="4" multiple="multiple">

Or, for finer control:

<select name="category[]" id="categories" size="4" multiple="multiple">
                <option value="{category_id}"{selected}>{category_name}</option>

By using the {category_group_id} and {category_depth} parameters, you can refine things further. If you need to restrict it by category group, and indent things by depth (and {select_options} is inadequate), perhaps something like this would do the trick:

<select name="category[]" id="categories" size="4" multiple="multiple">
                {if category_group_id == 3}
                     <option value="{category_id}"{selected}>
                            {if category_depth == 2}&nbsp;&nbsp;{/if}{category_name}
  • is there a reason why using the 2nd option above a parent category isn't auto-assigned if a child category is selected? auto-assign to parent category is set to "Yes" in channel admin global preferences
    – Tad Ward
    Commented Feb 18, 2014 at 23:09
  • Not sure @TadWard, sorry. Commented Feb 19, 2014 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.