Ok I’ve replaced:
<?php echo do_shortcode('[ratemypost-result]'); ?>
with
<?php echo Rate_My_Post_Public_Helper::get_visual_rating($post->ID); ?>
in my loop. Now stars appear but how can I make the average appear as well? I would like STARS + 4 (3) for example.
Ok I did the following which gave me the Stars + Average (although not the number of votes).
<?php echo "<div class='rmp-results-widget__visual-rating'>" . Rate_My_Post_Public_Helper::get_visual_rating($post->ID) . "</div> <div class='rmp-results-widget__avg-rating'>" . rmp_get_avg_rating($post->ID) . "</div>"; ?>
If someone knows a better way, let me know.
Hi @tsmulugeta,
which version of Rate my Post are you using? Some methods you mentioned are deprecated since version 3. See the documentation for more information. I have no problems displaying the results in within a loop. See example below:
add_shortcode( 'myshortcode', 'my_shortcode_handler' );
function my_shortcode_handler() {
$args = array(
'post_type' => 'post'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
echo '<p style="color:red; margin:0;">' . get_the_title() . '</p>';
echo do_shortcode( '[ratemypost-result]' );
}
}
}
Try calling [myshortcode] within post editor. Note that you need RMP version 3+ for this.
Regards,
Blaz
Hi Blaz,
I’m using Version 3.1.0
I will try the example you suggested and let you know how it goes. Thanks!
For some reason echo do_shortcode( ‘[ratemypost-result]’ ) does not workin with my version of Rate My Post. But echo do_shortcode( ‘[ratemypost]’ ) does work.
echo do_shortcode( ‘[ratemypost]’ ) however causes my page to take a long time to load.
Please advise.
Hi @tsmulugeta,
the example above utilizes do_shortcode( ‘[ratemypost-result]’ ); and it for sure works because I tested it before sharing the code. Many things could cause a slow page load within a custom loop so for such things I would recommend getting a web developer. It’s a very specific issue you are encountering and thus it’s hard for me provide better support.
Blaz