WordPress.org

Ready to get started?Download WordPress

Forums

TBTestimonials
[resolved] Random testimonial from a category (2 posts)

  1. powderflask
    Member
    Posted 2 years ago #

    On my to-do list was to add a hack in a shortcode option to select from a category - when I sat down to write it, there was an update!!

    But it only allows ALL testimonials from a category. This is unnecessarily restrictive - a single random testimonial from a category is a useful use-case (and the one I needed!)

    The easiest mod to allow this is to simply append a case to the handlers for various shortcode cases (in shortcode()):

    else if( ! is_null( $id ) && ! is_null( $cat ) && strtolower( $id ) == 'random' || strtolower( $id ) == 'rand' ) # random from category
            {
                $q = new WP_Query( array(
                	'post_type' => 'testimonial',
                	'post_status' => 'publish',
                	'orderby' => 'rand',
                	'posts_per_page' => 1,
                	'testimonial_category' => $cat
                ) );
    
                if( $q->have_posts() )
                {
                    $return = '<div id="tbtestimonial-listing">';
                    while( $q->have_posts() )
                    {
                        $q->the_post();
                        isset( $this->settings['use_template_api'] ) ?
                            $return .= $this->prepare_testimonial( is_null( $template ) ? 'listing' : $template ) :
                            $return .= $this->deprecated__prepare_testimonial( 'shortcode-all' );
                    }
                    wp_reset_query();
                    return $return . '</div>';
                }
                else
                    return;
            }

    Although there are other ways that won't duplicate all that code ;-)

    This is tested and works.

    Thanks so much for a great plugin - really is done the way it ought to be. hope this is helpful.

    http://wordpress.org/extend/plugins/tb-testimonials/

  2. Travis Ballard
    Member
    Plugin Author

    Posted 2 years ago #

    This will be added in 1.6.1, Thanks for your contribution :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.