Plugin Planet

Premium WordPress Plugins

USP Pro makes it easy to collect any sort of data with user-submitted posts. For example, you could add some custom fields to submitted posts to collect information such as telephone number, street address, favorite color, and virtually anything else that’s required. Once the post is submitted, the additional information is attached to the post as custom fields. This makes it easy to use and display the information anywhere in your theme.

As of version 1.3 of USP Pro, any of the following USP shortcodes may be used to display custom-field data:

  • [usp_submitted]
  • [usp_images]
  • [usp_file]
  • [usp_filename]
  • [usp_meta]
  • [usp_all_meta]
  • [usp_image]

Each of these shortcodes have a functionally identical template tag for advanced implementation via the theme template. Further, each shortcode/tag accepts a variety of attributes to enable fine-grain control over the displayed output. In addition to these shortcodes/tags, WordPress provides its own robust set of tags that make it possible to display user-submitted content and custom fields just about any way imaginable.

Watch a video tutorial on displaying custom fields »

Example

Here is a quick example of how to display custom-field data using the USP shortcode, [usp_meta]:

  1. Get the name of the custom field that you would like to display, for example, usp-custom-field
  2. Add the following shortcode to any Post, Page, or Custom Post Type: [usp_meta meta="usp-custom-field"]

The [usp_meta] shortcode will display the custom-field data for the current post/page on which it’s been included. To display custom fields for all user-submitted posts, use the equivalent USP template tag usp_get_meta() instead:

  1. Get the name of the custom field that you would like to display, for example, usp-custom-field
  2. Add the following template tag anywhere in the WP Loop: echo usp_get_meta(false, 'usp-custom-field');

Pro Tip: It’s also possible to display custom fields for any specific submitted post/page by specifying its ID via the first attribute. Here is an example doing so for post with ID 99:

  • Shortcode: [usp_meta id="99" meta="usp-custom-field"]
  • Template Tag: usp_get_meta(99, 'usp-custom-field');

Formatted Custom Fields

As of version 1.3, USP Pro allows for formatted custom fields. This means that any markup and/or line breaks included in submitted custom-field content will be preserved when stored in the database.

To make this safe from a security perspective, it is necessary to encode any markup included in custom fields. This is done automatically by USP Pro, but that leaves it up to you to decode the data when displaying in your theme template. Fortunately, this is very easy to do by simply applying PHP’s htmlspecialchars_decode() to the desired output. For example, to display the value of an HTML-formatted custom field, we can add the following to our theme template:

<?php $custom_field = usp_get_meta(false, 'usp-custom-field');
$custom_field = htmlspecialchars_decode($custom_field); ?>

Alternately you can add nl2br() to preserve line breaks:

<?php $custom_field = usp_get_meta(false, 'usp-custom-field');
$custom_field = htmlspecialchars_decode($custom_field);
$custom_field = nl2br($custom_field); ?>

And done. For more information on USP Pro template tags and shortcodes, visit the Docs:

Related Posts