This post explains how to add categories to your USP Form.
Add Global/Default Categories
To set the default categories that are displayed whenever you add the category field via shortcode,
- Visit plugin General settings ▸ Category Settings ▸ “Post Categories”
- Select any categories that should be displayed by default in any form (click the toggle link to view category list)
After saving your changes, any selected categories will be displayed in any USP Form that includes the
[usp_category] shortcode. The default categories can be overridden as follows.
Add Categories to Individual Forms
To override the default categories on a per-form basis. Add the
include attribute to the category shortcode, like so:
[usp_category] shortcode can be used only once per form. The only exception is when using Combo Categories.
Any categories specified via
include will be displayed on the form, along with any that are specified globally. Note that you can use
include="all" to display all non-empty categories, or
include="all_include_empty" to display all categories, even if empty.
Exclude Categories on Individual Forms
To exclude any categories from displaying. Add the
exclude attribute to the category shortcode, like so:
Check out the Shortcode documentation for details.
Allow Users to Add New Categories
You also can enable users to specify their own categories.
Assign Specific Categories to All Forms
Another way of adding categories is to automatically assign categories via hidden field. There are two ways of doing this, globally or locally.
To set required categories that will be assigned to all USP Forms:
- Visit General settings ▸ Category Settings
- Click the box for “Required Categories”
- In the next setting, “Required Category IDs”, enter the IDs of any categories that should be included for all USP Forms
Alternately, you can hide the Category field that is displayed using the
[usp_category] shortcode. To do so, enable the setting, “Hide Category Field” and save your changes. This enables you to configure the field using attributes like
exclude to fine-tune which categories are included automatically.
To set required categories locally (on a per-form basis), add the
cats attribute to the category shortcode, for example:
This shortcode will display the category field along with a hidden field that auto-assigns the categories
2 to any posts submitted via the form. Note that we’re using category IDs for all shortcode attributes.
Where do I find my category IDs? There are a couple of ways. First you can visit Posts ▸ Categories, and then long-hover your cursor over any category link. In most browsers, doing this will reveal the full URL at the bottom of the browser window (or somewhere). In the URL, you will see an
ID with a number — that is the category ID. Alternately, you can get category IDs directly in the USP Pro General settings. Visit the Category Settings, toggle open the “Post Categories” list, and hover your cursor over any category link. The associated category ID will be displayed in the resulting tooltip info.
Allow User to Select Multiple Categories
To allow the user to select multiple categories:
- Visit plugin General settings ▸ Category Settings ▸ Category Menu, and select either Dropdown or Checkboxes.
- If you select Checkboxes, then the user can select multiple categories with no further action required on your part.
- If you select Dropdown, the next step is add
multiple="true"to your category shortcode, for example:
That will enable your visitors to select multiple categories (when more than one category is displayed).