Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Bill Erickson

    (@billerickson)

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

    Plugin Author Bill Erickson

    (@billerickson)

    It currently supports custom post types. use ‘post_type=whatever’

    Plugin Author Bill Erickson

    (@billerickson)

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

    Thread Starter ekajatik

    (@ekajatik)

    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”] ?

    Plugin Author Bill Erickson

    (@billerickson)

    Yes it does.

    Thread Starter ekajatik

    (@ekajatik)

    Great work Bill, many thanks.

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

    Plugin Author Bill Erickson

    (@billerickson)

    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.

    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:

    <?php
    /**
     * Plugin Name: Display Posts Shortcode
     * Plugin URI: https://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: https://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 <[email protected]>
     * @copyright Copyright (c) 2011, Bill Erickson
     * @link https://www.billerickson.net/shortcode-to-display-posts/
     * @license https://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(
    				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 );
    
    		endwhile;
    
    		$return .= '</ul>';
    	endif; wp_reset_query();
    
    	if (!empty($return)) return $return;
    }
    ?>

    What is wrong?

    Thanks for a hint.

    Best regards,
    CK

    Find the error: A comma was missing!

    Plugin Author Bill Erickson

    (@billerickson)

    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"]

    Bill,

    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?

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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Plugin: Display Posts Shortcode] Custom post types, Custom Taxonomies’ is closed to new replies.