WP Show Posts Shortcode

Below, you’ll find a detailed guide on how to add the WP Show Posts Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Show Posts Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the WP Show Posts Plugin and the shortcodes it provides:

Plugin Icon
WP Show Posts

"WP Show Posts is a versatile WordPress plugin that allows you to list posts anywhere on your site. It offers customizable settings for post type, taxonomy, and terms to streamline content display."

★★★★☆ (79) Active Installs: 100000+ Tested with: 6.1.4 PHP Version: false
Included Shortcodes:
  • [wp_show_posts]

WP Show Posts [wp_show_posts] Shortcode

The WP Show Posts shortcode is designed to display posts by ID or name. It accepts three parameters: ‘id’, ‘name’, and ‘settings’. The ‘id’ parameter fetches posts by their unique ID, while ‘name’ retrieves posts by their title. If a name is provided, the function gets the corresponding ID. The ‘settings’ parameter allows for additional customization. After fetching the posts, the function uses ‘wpsp_display’ to render them. The output is then returned and displayed where the shortcode is used.

Shortcode: [wp_show_posts]

Parameters

Here is a list of all possible wp_show_posts shortcode parameters and attributes:

  • id – It uniquely identifies the WP Show Posts list to display.
  • name – It specifies the name of the WP Show Posts list to display.
  • settings – It allows additional settings to customize the displayed list.

Examples and Usage

Basic example – A simple usage of the shortcode to display posts by referencing the ID of the WP Show Posts list.

[wp_show_posts id="123" /]

Advanced examples

Displaying posts using the shortcode by referencing the name of the WP Show Posts list. This is useful when you don’t remember the ID but you know the name of the list.

[wp_show_posts name="my-list" /]

Displaying posts using the shortcode by referencing both ID and name. The posts will first try to load by ID, but if not found, it will try to load by name. This is useful for redundancy and ensuring that the posts are displayed even if there’s an error with the ID.

[wp_show_posts id="123" name="my-list" /]

Using the shortcode to display posts with custom settings. This allows you to override the settings defined in the WP Show Posts list.

[wp_show_posts id="123" settings="custom-settings" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_show_posts] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wp_show_posts', 'wpsp_shortcode_function' );

Shortcode PHP function:

function wpsp_shortcode_function( $atts ) {
	$atts = shortcode_atts(
		array(
			'id' => '',
			'name' => '',
			'settings' => ''
		), $atts, 'wp_show_posts'
	);

	ob_start();

	// Get the ID from the list name if it's provided.
	if ( ! empty( $atts['name'] ) ) {
		$list = get_page_by_title( $atts['name'], 'OBJECT', 'wp_show_posts' );
		$atts['id'] = $list->ID;
	}

	if ( $atts['id'] ) {
		wpsp_display( $atts['id'], $atts['settings'] );
	}

	return ob_get_clean();
}

Code file location:

wp-show-posts/wp-show-posts/wp-show-posts.php

Conclusion

Now that you’ve learned how to embed the WP Show Posts Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *