Display Posts Shortcode
[resolved] Custom post types, Custom Taxonomies (14 posts)

  1. ekajatik
    Posted 4 years ago #

    Hi there, does it support custom post types and taxonomies, e.g. posts from X custom post type, tagged Y from its own custom taxonomy?



  2. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    Not yet, but it's on the list of features for the next version

  3. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    It currently supports custom post types. use 'post_type=whatever'

  4. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    It also now supports taxonomies: [display_posts taxonomy="color" tax_term="blue"]

  5. ekajatik
    Posted 4 years ago #

    Hi Bill, does it support both CPT's and custom taxonomies at the same time, e.g. [display_posts post_type="whatever" taxonomy="color" tax_term="blue"] ?

  6. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    Yes it does.

  7. ekajatik
    Posted 4 years ago #

    Great work Bill, many thanks.

  8. shane7ny
    Posted 4 years ago #

    Is there any way to have this use pagination? So that we can have it display 100's of results spread out over pages?

  9. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    Unfortunately no, the plugin can't support pagination since that would interact with the actual page's pagination. Your best bet is to create a template file for this, or leverage the existing pagination of WordPress.

    For instance, if you wanted to have intro text then hundreds of paginated posts in the "sample" category, create a template file called "category-sample.php" for it and put your content in there. You'd then use /category/sample to access it, and /category/sample/page/2 for the second page.

  10. Christian Kramer
    Posted 4 years ago #

    Hi Bill, I use your fabulous plugin and it works fine. Now I have a small problem. I use tags in a special post type. The argument for the tags is 'product_tags', the post type is 'portfolio'.
    Filtering with post_type = "portfolio" works, but for product_tags I have to add the argument 'product_tags' to your plugin.
    Here is my solution, that will not work:

     * Plugin Name: Display Posts Shortcode
     * Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
     * Description: Display a listing of posts using the [display-posts] shortcode
     * Version: 1.5
     * Author: Bill Erickson
     * Author URI: http://www.billerickson.net
     * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
     * General Public License version 2, as published by the Free Software Foundation.  You may NOT assume
     * that you can use any other version of the GPL.
     * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
     * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     * @package Display Posts
     * @version 1.5
     * @author Bill Erickson <bill@billerickson.net>
     * @copyright Copyright (c) 2011, Bill Erickson
     * @link http://www.billerickson.net/shortcode-to-display-posts/
     * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    // Create the shortcode
    add_shortcode('display-posts', 'be_display_posts_shortcode');
    function be_display_posts_shortcode($atts) {
    	extract( shortcode_atts( array(
    		'post_type' => 'post',
    		'tag' => '',
                    'product_tags' => '',
    		'category' => '',
    		'posts_per_page' => '10',
    		'order' => 'DESC',
    		'orderby' => 'date',
    		'include_date' => false,
    		'include_excerpt' => false,
    		'image_size' => false,
    		'taxonomy' => false,
    		'tax_term' => false
    	), $atts ) );
    	$args = array(
    		'post_type' => $post_type,
    		'tag' => $tag,
                    'product_tags' => $product_tags
    		'category_name' => $category,
    		'posts_per_page' => $posts_per_page,
    		'order' => $order,
    		'orderby' => $orderby,
    	if ( !empty( $taxonomy ) && !empty( $tax_term ) ) {
    		$tax_args = array(
    			'tax_query' => array(
    					'taxonomy' => $taxonomy,
    					'field' => 'slug',
    					'terms' => $tax_term
    		$args = array_merge( $args, $tax_args );
    	$return = '';
    	$listing = new WP_Query($args);
    	if ( $listing->have_posts() ):
    		$return .= '<ul class="display-posts-listing">';
    		while ( $listing->have_posts() ): $listing->the_post(); global $post;
    			if ( $image_size && has_post_thumbnail() )  $image = '<a class="image" href="'. get_permalink() .'">'. get_the_post_thumbnail($post->ID, $image_size).'</a> ';
    			else $image = '';
    			$title = '<!--<a class="title" href="'. get_permalink() .'">-->'. get_the_title() . '<!--</a>-->';
    			if ($include_date) $date = ' <span class="date">('. get_the_date('n/j/Y') .')</span>';
    			else $date = '';
    			if ($include_excerpt) $excerpt = ' - <span class="excerpt">' . get_the_excerpt() . '</span>';
    			else $excerpt = '';
    			$output = '<li>' . $image . $title . $date . $excerpt . '</li>';
    			$return .= apply_filters( 'display_posts_shortcode_output', $output, $atts, $image, $title, $date, $excerpt );
    		$return .= '</ul>';
    	endif; wp_reset_query();
    	if (!empty($return)) return $return;

    What is wrong?

    Thanks for a hint.

    Best regards,

  11. Christian Kramer
    Posted 4 years ago #

    Find the error: A comma was missing!

  12. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    product_tags is simply a taxonomy, correct? Use the taxonomy options instead of modifying the plugin. To display the products post type, product_tags taxonomy and the blue taxonomy term, use this:

    [display-posts post_type="products" taxonomy="product_tags" tax_term="blue"]

  13. tbadorrek
    Posted 3 years ago #


    Are custom post types now supported? I'm trying to do the following but to no avail:

    [display-posts post_type="research" taxonomy="research-categories" tax_term="taxes" include_excerpt="true" image_size="thumbnail" posts_per_page="-1" ]

    I'm using "Custom Post Types UI" plugin to create a custom post type, "research" and to create a custom taxonomy, "research-categories", and I have created the taxonomy term "taxes" and tagged one of the custom posts. However, nothing appears.

    Any thoughts on what might be conflicting with the shortcode?

  14. tbadorrek
    Posted 3 years ago #

    Nevermind. The plugin only would work when pages were publicly published, not privately published.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic