Display Post Types Shortcode

Below, you’ll find a detailed guide on how to add the Display Post Types 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 Display Post Types Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Display Post Types Plugin and the shortcodes it provides:

Plugin Icon
Display Post Types – Post Grid, post list and post sliders

"Display Post Types is a versatile WordPress plugin that organizes your content into grids, lists, and sliders. It simplifies post navigation and enhances visual appeal for your site's visitors."

★★★★★ (11) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 7.2
Included Shortcodes:
  • [dpt]

Display Post Types [dpt] Shortcode

The Display Post Types shortcode is a powerful tool in WordPress that allows you to customize the display of your posts. This shortcode fetches posts based on specified criteria like post IDs, page IDs, or taxonomy terms. It supports various display styles and parameters, enabling you to tailor the output to your needs. The results can be ordered, filtered, and styled according to the applied attributes. The shortcode’s flexibility makes it a valuable asset for any WordPress site, enhancing content presentation and user experience.

Shortcode: [dpt]


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

  • post_type – Defines the type of post to display.
  • taxonomy – Specifies the taxonomy for filtering the posts.
  • terms – Lists the taxonomy terms for filtering the posts.
  • relation – Sets the relationship between multiple taxonomies.
  • post_ids – Identifies specific posts to be displayed.
  • pages – Identifies specific pages to be displayed.
  • number – Sets the number of posts/pages to display.
  • orderby – Determines the order of displayed posts/pages.
  • order – Sets the direction of ordering (ascending or descending).
  • styles – Defines the styling of the displayed posts/pages.
  • style_sup – Supplements the main style definition.
  • image_crop – Determines the cropping position of the image.
  • img_aspect – Sets the aspect ratio of the image.
  • img_align – Aligns the image in the post/page.
  • br_radius – Sets the border radius of the image.
  • col_narr – Defines the column arrangement.
  • pl_holder – Decides if placeholder text will be displayed.
  • show_pgnation – Decides if pagination will be displayed.
  • text_align – Aligns the text in the post/page.
  • v_gutter – Sets the vertical space between posts/pages.
  • h_gutter – Sets the horizontal space between posts/pages.
  • e_length – Determines the length of the excerpt.
  • e_teaser – Sets the teaser text for the excerpt.
  • classes – Adds additional CSS classes to the post/page.
  • offset – Skips a certain number of posts/pages.
  • autotime – Sets the automatic refresh time for the posts/pages.

Examples and Usage

Basic example – The following shortcode displays posts using default parameters.

[dpt /]

Advanced examples

Displaying posts from a specific category (terms) and limiting the number of displayed posts.

[dpt terms="category1, category2" number=5 /]

Displaying specific posts by their IDs and ordering them by title in ascending order.

[dpt post_ids="1,2,3" orderby="title" order="ASC" /]

Displaying posts from a specific post type and applying a custom style.

[dpt post_type="custom_post_type" styles="custom_style" /]

Displaying pages by their IDs and excluding the page set as ‘page for posts’ in WordPress settings.

[dpt pages="10,20,30" /]

Displaying posts with pagination and alignment of the text to the center.

[dpt show_pgnation="yes" text_align="center" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'dpt', array( $inst, 'render' ) );

Shortcode PHP function:

                    function render( $atts, $dpt_content = null ) {

		$defaults = Get_Fn::defaults();
		$atts     = shortcode_atts( $defaults, $atts, 'dpt' );

		$terms = array();
		if ( ! empty( $atts['terms'] ) ) {
			$terms = explode( ',', $atts['terms'] );
			$terms = array_map( 'trim', $terms );

		$ids = array();
		if ( ! empty( $atts['post_ids'] ) ) {
			$ids = explode( ',', $atts['post_ids'] );
			$ids = array_map( 'trim', $ids );

		$pages = array();
		if ( ! empty( $atts['pages'] ) ) {
			$pages = explode( ',', $atts['pages'] );
			$pages = array_map( 'trim', $ids );

		// Check if all pages IDs are valid.
		if ( 'page' === $atts['post_type'] && ! empty( $pages ) ) {
			// Get list of all pages.
			$all_pages        = get_all_page_ids();
			$all_pages        = explode( ',', $all_pages );
			$valid_pages      = array_diff( $all_pages, array( get_option( 'page_for_posts' ) ) );
			$pages            = array_intersect( $pages, $valid_pages );
			$atts['taxonomy'] = array();

		 * DPT display params from shortcode.
		 * @since 1.8.0
		$display_args = apply_filters(
				'post_type'     => $atts['post_type'],
				'taxonomy'      => $atts['taxonomy'],
				'terms'         => $terms,
				'relation'      => $atts['relation'],
				'post_ids'      => $ids,
				'pages'         => $pages,
				'number'        => $atts['number'],
				'orderby'       => $atts['orderby'],
				'order'         => $atts['order'],
				'styles'        => $atts['styles'],
				'style_sup'     => $atts['style_sup'],
				'image_crop'    => isset( $atts['img_croppos'] ) ? $atts['img_croppos'] : 'centercrop',
				'img_aspect'    => $atts['img_aspect'],
				'img_align'     => $atts['img_align'],
				'br_radius'     => $atts['br_radius'],
				'col_narr'      => $atts['col_narr'],
				'pl_holder'     => ( 'false' === $atts['pl_holder'] || ! $atts['pl_holder'] ) ? '' : 'yes',
				'show_pgnation' => ( 'false' === $atts['show_pgnation'] || ! $atts['show_pgnation'] ) ? '' : 'yes',
				'text_align'    => $atts['text_align'],
				'v_gutter'      => $atts['v_gutter'],
				'h_gutter'      => $atts['h_gutter'],
				'e_length'      => $atts['e_length'],
				'e_teaser'      => $atts['e_teaser'],
				'classes'       => $atts['classes'],
				'offset'        => $atts['offset'],
				'autotime'      => $atts['autotime'],

		Display::init( $display_args );
		$content = ob_get_clean();
		return $content;

Code file location:



Now that you’ve learned how to embed the Display Post Types 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.


Leave a Reply

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