Plugin Planet

Premium WordPress Plugins

USP Pro version 2.3 introduces a new shortcode to display a list of submitted posts for any user and for any post type. This post explains how it works and how to customize the shortcode’s attributes to suit your needs.

Meet the Shortcode

To display a list of submitted post titles, add the following Shortcode to any WP Post, Page, or Custom Post Type:

[usp_pro_display_posts]

Customizing

The [usp_pro_display_posts] Shortcode provides several attributes that enable you to customize the list of submitted posts:

userid			specifies the user(s) for which posts should be displayed

			all         : display submitted posts from all users (default)
			logged      : display submitted posts from current logged-in user
			current     : display submitted posts from author of current archive page
			Author Name : display submitted posts from specified USP Author Name (value of "usp-author" Custom Field)
			Author ID   : display submitted posts from specified WP Author ID (e.g., 1, 2, 3, etc.)

numposts		specifies the number of posts to display

			integer : displays the specified number of submitted posts (default: 10)

display			specifies how the posts should be displayed

			title         : displays a list of submitted post titles (default)
			content       : displays the submitted post title and content
			excerpt       : displays the submitted post title and excerpt
			thumb         : displays only the featured image
			content+thumb : displays title, content, and featured image
			excerpt+thumb : displays title, excerpt, and featured image
			title+thumb   : displays title and featured image

loggedin		specifies whether to display the posts for logged-in users

			false : display submitted posts for all users (default)
			true  : display submitted posts only if user is logged in

status			specifies the post status for which posts should be displayed

			publish : display only published submitted posts (default)
			pending : display only pending submitted posts
			draft   : display only draft submitted posts
			etc..   : display any valid Post Status: https://bit.ly/3eavb9u

modlinks		specifies whether to display moderation links for each post

			false : do not display "edit" and "delete" links for the post (default)
			true  : display "edit" and "delete" links for the post

formid			specifies a specific form for which posts should be displayed

			integer : limits displayed posts to a specific USP Form (no default)

cat			specifies the category(ies) for which posts should be displayed

			integer  : limits displayed posts to a specific category (e.g., 2) (no default)
			integers : limits displayed posts to multiple categories (e.g., 2,6,17,38) 
			current  : limits displayed posts to current category/categories

order			specifies the order in which posts should be displayed

			DESC : orders posts in descending order (default)
			ASC  : orders posts in ascending order

orderby			specifies the order in which posts should be displayed

			param : orders posts by any valid parameter (e.g., ID, author, title, et al) (default = date)

post_type		specifies the post type for which posts should be displayed

			any valid post type or 'any' for any post type (default = any)

post_link		specifies the URL to use for linked post titles

			permalink : use the post permalink/URL (default)
			user_url  : use the user-submitted URL (if available)

link_title		specifies whether to link the post titles

			true  : link post titles (default)
			false : do not link post titles

You can find more info about these parameters at the WP Codex.

Examples

Here are some examples showing different shortcode configurations:

[usp_pro_display_posts userid="1"]                       : displays all submitted posts by registered user with ID = 1
[usp_pro_display_posts userid="current"]                 : displays all submitted posts by author of current archive page
[usp_pro_display_posts status="pending" userid="logged"] : displays all pending submitted posts from the current logged-in user
[usp_pro_display_posts userid="Pat Smith"]               : displays all submitted posts by author name "Pat Smith"
[usp_pro_display_posts loggedin="true"]                  : displays all submitted posts only to logged-in users
[usp_pro_display_posts userid="all"]                     : displays all submitted posts by all users/authors
[usp_pro_display_posts numposts="5"]                     : displays 5 most recent submitted posts
[usp_pro_display_posts display="excerpt"]                : display excerpts of submitted posts

As a bonus, the [usp_pro_display_posts] Shortcode displays any posts that were submitted by the free version of USP.

Theme Template

Just a tip: you can display any shortcode directly in your theme template using WP’s do_shortcode() function. So to display a list of user-submitted posts, you can do something like this:

<?php echo do_shortcode('[usp_pro_display_posts]'); ?>

And then flesh it out with any necessary shortcode attributes.

Advanced Customization

For advanced customization, the following filter hooks are provided:

usp_display_posts_default
usp_display_posts_args
usp_display_posts_noposts
usp_shortcode_display_posts_size
usp_shortcode_display_posts_title
usp_shortcode_display_posts_edit_title
usp_shortcode_display_posts_edit_text
usp_shortcode_display_posts_delete_title
usp_shortcode_display_posts_delete_text
usp_shortcode_display_posts_modlink_sep1
usp_shortcode_display_posts_modlink_sep2
usp_shortcode_display_posts_before
usp_shortcode_display_posts_after

Check out the source code in /inc/usp-functions.php for more information.