In this quick tutorial, we’ll see how to add combo/chained categories to any USP Form.
Single Category Field
First consider the shortcode used to add a single category field to a form:
By default, this shortcode displays a category field that displays all categories selected in the setting, General ▸ Post Categories. Many of the demo forms included with USP Pro include the
Combo Category Fields
In some forms, it may be necessary to add multiple category fields, such that the submitted post is assigned a combination of categories. For example, instead of displaying a whole bunch of categories in a single category field, it might be useful to split up the categories and display them using several different fields. Then when the post is submitted the multiple category fields are combined and applied to the post.
To keep things simple, consider an example case where six categories need to be displayed in three different category fields. Here is the setup that we want to achieve:
- First category field – displays categories 3, 4, 5, 6 (i.e., excludes cats 1 and 2)
- Second category field – displays categories 1, 2, 5, 6 (i.e., excludes cats 3 and 4)
- Third category field – displays categories 1, 2, 3, 4 (i.e., excludes cats 5 and 6)
To accomplish this, we’ll chain the category fields together by adding the
combo attribute to each of three
[usp_category combo="1" type="dropdown" exclude="1,2"] [usp_category combo="2" type="dropdown" exclude="3,4"] [usp_category combo="3" type="dropdown" exclude="5,6"]
Here we are adding three category fields to the form. They are chained together using the
combo attribute. The attribute values are
3, which lets USP Pro know that the categories submitted via these three fields should be combined and assigned to the submitted post. Additionally, we use the
type attribute to make each field a dropdown menu, and use
exclude to omit categories used in other fields. To really “see” what this code does, add it to any form and preview the results on the front-end. Of course, you can use any other attributes for the [usp_category] shortcode that are needed to get the job done.
Currently USP Pro supports up to 5 combo category fields.
Note: Instead of using the
exclude attribute to exclude categories from each combo field, you can use the
include attribute, like so:
[usp_category combo="1" type="dropdown" include="1,2,3"] [usp_category combo="2" type="dropdown" include="4,5,6"] [usp_category combo="3" type="dropdown" include="7,8,9"]
This can make things a bit easier to manage when working with combo categories.