kk Star Ratings
[resolved] Trying to do manual loop of $top_rated_posts. Empty array. (5 posts)

  1. adambundy
    Posted 4 years ago #

    Im trying to create a custom loop of the top rated posts to show the post thumb among other things, but a print_r of the $top_rated_posts is empty. Is there a chance that the name of the array has changed with the latest version of the plugin?



  2. Kamal Khan
    Plugin Author

    Posted 4 years ago #

    It should work.

    Can you paste the code snippet so that I can have a look.

  3. adambundy
    Posted 4 years ago #

    Thanks for your response! It was my mistake- I hadn't replaced $total with a value. As soon as I did, the query worked. For anyone trying to do a similar simple top-rated posts query, here is my code:

    <?php if(function_exists('kk_star_ratings_get')) : $top_rated_posts = kk_star_ratings_get(5); endif; 
    foreach($top_rated_posts as $post) {
       $post_id = $post->ID;
       $queried_post = get_post($post_id);
       echo "<li id='rated-post-id-" . $post_id . "'>";
       echo "<a href='".get_permalink($post_id)."'>";
       echo get_the_post_thumbnail($post_id, 'thumbnail');
       echo "</a><a href='".get_permalink($post_id)."'>".$queried_post->post_title."</a>";
       echo " <span style='font-size:10px;'>(".$post->ratings."/5)</span>";
       echo "<p class='excerpt'>";
       echo substr($queried_post->post_content, 0, 200);
       echo "&hellip;</p>";
       echo "</li>";
  4. Kamal Khan
    Plugin Author

    Posted 4 years ago #

    Thank you :)

  5. tattymamprin
    Posted 4 years ago #

    Thank you for you code, Adam! was exactly what I was looking for. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • kk Star Ratings
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic