• I am using your testimonial plugin and creating a custom slider.
    I am running query post to get all the value from testimonial like name image etc and used a get_post_meta for getting meta value like position.
    But how can I get star rating also. When I am getting star rating by get_post_meta it return me only digit. I want actual stars.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter ashu2389

    (@ashu2389)

    <?php
    $args = array(
    ‘post_type’ => ‘testimonial’,
    ‘posts_per_page’ => 3,

    );
    $query = new WP_Query( $args );
    if ( $query->have_posts() )
    while ( $query->have_posts() ) : $query->the_post();
    $image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    $resizedimage = mr_image_resize($image,140,140);
    $id = get_the_ID(); ?>

    <div class=”testimonial-content-bg”>
    <div class=”testimonial-contentt”>
    <p class=”testimonial-content”><span>/images/quotes.png”/></span><?php echo get_the_content(); ?></p>
    <?php $testimonial_name = get_post_meta( $id, ‘_ikcf_client’, true );
    $testimonial_position = get_post_meta( $id, ‘_ikcf_position’, true );
    //$testimonial_rating = get_post_meta( $id, ‘_ikcf_rating’, true ); ?>
    <div class=”testimonial-review”>
    <?php if($testimonial_name){ ?> <h4>-<?php echo $testimonial_name; ?></h4><?php } ?>
    <span><?php if($testimonial_position){ echo $testimonial_position; } ?><?php// if($testimonial_rating){ echo $testimonial_rating; } ?></span>
    <?php if($image){ ?> <p class=”client-img”>” alt=”<?php the_title(); ?>”/></p><?php } ?>
    </div>
    </div>
    </div>
    <?php endwhile; wp_reset_query(); ?>

    Plugin Contributor richardgabriel

    (@richardgabriel)

    Hey @ashu2389!

    We actually have code internalised to our single_testimonial.php template file that converts the digit into stars and displays them. That would be the place to look!

    Its basically a foreach loop that outputs a fontawesome icon — I’m pretty sure you can cook one of those up based on what you’ve already done!

    Please let me know if that helps.

    All the best,
    Richard

    Thread Starter ashu2389

    (@ashu2389)

    I am not sure How can I get only star rating with below piece of code

    <?php if($meta_data_position == “below”) {
    $this->easy_testimonials_build_metadata_html($display_testimonial, $author_class, $show_date, $show_rating, $show_other);
    } ?>

    Plugin Contributor richardgabriel

    (@richardgabriel)

    Hey @ashu2389!

    I see, that is slightly older code (but the function it calls would have the answer.)

    In the new template, this is the code you are looking for:

    <?php if($show_the_rating): ?>
    	<?php if(strlen($display_testimonial['num_stars'])>0): ?>
    	<span class="stars">
    	<?php			
    		$x = 5; //total available stars
    		//output dark stars for the filled in ones
    		for($i = 0; $i < $display_testimonial['num_stars']; $i ++){
    			echo '<span class="dashicons dashicons-star-filled"></span>';
    			$x--; //one less star available
    		}
    		//fill out the remaining empty stars
    		for($i = 0; $i < $x; $i++){
    			echo '<span class="dashicons dashicons-star-filled empty"></span>';
    		}
    	?>			
    	</span>	
    	<?php endif; ?>
    <?php endif; ?>

    Some version of that should do the trick for you.

    All the best,
    Richard

    Thread Starter ashu2389

    (@ashu2389)

    You are using $display_testimonial variable. But I am not sure which variable Should I use to get value.
    In my template there are no any $display_testimonial

    Plugin Contributor richardgabriel

    (@richardgabriel)

    Hey @ashu2389

    That above code is meant to be used as an example to draw from, not copy and paste. If you read it, you’ll see it shows how to output the correct stars based on the integer value of the rating (which is what you said you already had in your original post using the get_post_meta call.)

    I’m assuming you’ll need to modify it to match your actual variable names, class names, etc. Since you’re making a custom slider, this is a required step.

    Best,
    Richard

    Best,
    RIchard

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get Custom testimonial with rating’ is closed to new replies.