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, [usp_category]:

  1. Visit plugin General settings ▸ Category Settings ▸ “Post Categories”
  2. 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 include="10,11,12"]
Important! The [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:

[usp_category exclude="10,11,12"]

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.

Globally

To set required categories that will be assigned to all USP Forms:

  1. Visit General settings ▸ Category Settings
  2. Click the box for “Required Categories”
  3. 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 include and exclude to fine-tune which categories are included automatically.

Locally

To set required categories locally (on a per-form basis), add the cats attribute to the category shortcode, for example:

[usp_category cats="1,2"]

This shortcode will display the category field along with a hidden field that auto-assigns the categories 1 and 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:

  1. Visit plugin General settings ▸ Category Settings ▸ Category Menu, and select either Dropdown or Checkboxes.
  2. If you select Checkboxes, then the user can select multiple categories with no further action required on your part.
  3. If you select Dropdown, the next step is add multiple="true" to your category shortcode, for example: [usp_category multiple="true"]

That will enable your visitors to select multiple categories (when more than one category is displayed).

References & Resources