Plugin Planet

Premium WordPress Plugins

As of version 1.7, USP Pro supports Custom Taxonomies. So you can create forms that enable the user to select a taxonomy (or taxonomies) for the submitted post. Read on to learn how it’s done..

First, and most importantly, any taxonomy that you would like to use must be supported by the theme. For more information on how this is done, ask your theme provider or consult the WP Codex.

Once your theme supports one or more taxonomies, you can use them in your USP Forms. To include a field for any custom taxonomy, include the following shortcode in any USP Form:

[usp_taxonomy tax="TAXONOMY" terms="TERMS"]

Replace “TAXONOMY” with the name of your custom taxonomy, and replace “TERMS” with the term IDs (comma-separated) that should be included as options. Note that there is a “USP:Taxonomy” Quicktag available in the “Edit Form” screen that will add the [usp_taxonomy] shortcode. Here is a screenshot.

Once included in the form, the taxonomy field will enable the users to select which terms should be associated with the submitted post. As with other shortcodes, there are a number of attributes that may be used to configure the taxonomy field exactly as required.

Attributes for [usp_taxonomy]

Here is a list of attributes that can be used to customize the taxonomy field when using the [usp_taxonomy] shortcode:

  • type – type of field to display, checkbox or dropdown (default: dropdown)
  • class – any additional class names, comma-separated
  • placeholder – placeholder text (default: “Taxonomy”)
  • label – label text (default: “Taxonomy”)
  • default – customize the “Please select…” text when type is set to “dropdown”
  • required – should the input be required (“yes” or “no”)
  • tax – specifies the taxonomy (e.g., “animals”)
  • size – size of the select menu (applies only to “select” menu option)
  • multiple – allow users to select multiple options (“yes” or “no”); does not apply to checkbox menu
  • terms – tax terms to include (comma-separated list of term IDs, or use “all” to include all non-empty tax terms, or use “all_include_empty” to include all terms terms, even if empty)
  • exclude – comma-separated list of term IDs to exclude (useful when setting terms to “all”)
  • custom – any valid attribute, for example: id='custom' (use single quotes)
  • fieldset – enable auto-fieldset: true, false, or custom class name (default: true)

For example, to add a taxonomy shortcode that:

  • Add a custom class custom-taxonomy to the taxonomy field
  • Adds a label “Custom Taxonomy” to the taxonomy field
  • Requires the taxonomy field in order to submit the form
  • Includes terms for the “Animals” taxonomy
  • Enables the user to select multiple terms
  • Includes taxonomy terms with the following IDs: 12, 13, 14, 15, 16, 17
  • Displays the list of taxonomy terms as a dropdown menu

Here is the shortcode required to add this field to a form:

[usp_taxonomy class="custom-taxonomy" label="Custom Taxonomy" required="true" tax="animals" size="" multiple="true" terms="12,13,14,15,16,17" type="dropdown"]

Note that all USP Pro shortcodes (and template tags) are also displayed/described in the plugin settings via the Tools tab.

Hidden Fields for Custom Taxonomies

It also is possible to specify default Taxonomies by including hidden fields in the form. Here is an example:

<input type="hidden" name="usp-taxonomy-people[]" value="1" />
<input type="hidden" name="usp-taxonomy-people[]" value="2" />
<input type="hidden" name="usp-taxonomy-people[]" value="3" />

Here we are specifying three default Taxonomies for people. To customize for your own use, change “1”, “2”, “3” to your tax term IDs, and change “people” to tax name. Then add to any form and then verify proper functionality by submitting a few test posts.

Multiple taxonomy fields

With USP Pro, you can include multiple taxonomy fields to any form. For example:

[usp_taxonomy tax="people" terms="51,52,53" type="checkbox" multiple="true" required="true"]

[usp_taxonomy tax="animals" terms="63,64,65" type="checkbox" multiple="true" required="true"]

The only real requirement is that the tax and terms attributes correspond to actual taxonomies and terms. You can add as many taxonomy fields as desired.

Let users specify their own taxonomy terms

As of USP Pro version 2.0, it is possible to enable visitors to specify their own taxonomy terms. To do so, add the following markup to your form, for example:

<input name="usp-taxonomy-people" type="text" />

That is the basic markup required to let users specify their own terms. There are two things that must be included:

  • The value of the name attribute must begin with usp-taxonomy- and end with the name of your taxonomy (e.g., people in this example).
  • The type of field must be set to text.

Once you’ve got the basic text input field, you can embellish it with all of the usual trimmings. For example, here is the same input field with all sorts of bells and whistles mixed in:

<label for="usp-taxonomy-people" class="usp-label usp-label-taxonomy">People (comma separated)</label> 
<input name="usp-taxonomy-people" type="text" value="" data-required="true" maxlength="99" placeholder="Terms" class="usp-input usp-input-taxonomy" />

You can even include multiple user-specified tax-term fields, for example:

<label for="usp-taxonomy-people" class="usp-label usp-label-taxonomy">People (comma separated)</label> 
<input name="usp-taxonomy-people" type="text" value="" data-required="true" maxlength="99" placeholder="Terms" class="usp-input usp-input-taxonomy" />

<label for="usp-taxonomy-animals" class="usp-label usp-label-taxonomy">Animals (comma separated)</label> 
<input name="usp-taxonomy-animals" type="text" value="" data-required="true" maxlength="99" placeholder="Terms" class="usp-input usp-input-taxonomy" />

There is no limit to the number of custom tax fields that may included in a USP Form!

Related