• I am not seeing the expected results when trying to display the top x, highest-rated posts. I’m not very familiar with php nor much of WordPress beyond modifying theme files, but this is the function I’m using:

    
    function show_toprated () {
    	$max_posts = 10;
    	$required_rating = 2;
    	$required_votes = 2;
    $my_res = rmp_get_top_rated_posts( $max_posts, $required_rating, $required_votes );
    	
    //var_dump($my_res);
    
    	foreach ($my_res as $my_named) {
    	echo '<tr><td><img src="' . $my_named['thumb'] . '" width="150"></td><td>' . $my_named['avgRating'] . 'out of 5 with ' . $my_named['votes'] . ' votes.</td><td>' . $my_named['postID'] . '</td><td>' . $my_named['postLink'] . '</td></tr><br>';
    }
    	
    }
    add_shortcode('show_top_rated', 'show_toprated');

    That pulls this info out:

    	array(3) {
      [0]=>
      array(6) {
        ["postID"]=>
        int(702)
        ["avgRating"]=>
        int(4)
        ["title"]=>
        string(26) "TITLE"
        ["postLink"]=>
        string(58) "LINK"
        ["thumb"]=>
        string(99) "THUMB"
        ["votes"]=>
        int(3)
      }
      [1]=>
      array(6) {
        ["postID"]=>
        int(746)
        ["avgRating"]=>
        float(3.8)
        ["title"]=>
        string(31) "TITLE"
        ["postLink"]=>
        string(58) "LINK"
        ["thumb"]=>
        string(87) "THUMB"
        ["votes"]=>
        int(5)
      }
      [2]=>
      array(6) {
        ["postID"]=>
        int(742)
        ["avgRating"]=>
        float(3.5)
        ["title"]=>
        string(25) "TITLE"
        ["postLink"]=>
        string(54) "LINK"
        ["thumb"]=>
        string(87) "THUMB"
        ["votes"]=>
        int(2)
      }
    }

    Only 3 results. However, when I look through the postmeta table, I see more posts than 3 that have more than 2 votes and a rating of higher than 2:

    
    

    mysql> select post_id,meta_key,meta_value from wp_postmeta where meta_key=’rmp_vote_count’ OR meta_key=’rmp_rating_val_sum’ OR meta_key=’rmp_avg_rating’ ORDER BY post_id;
    +———+——————–+————+
    | post_id | meta_key | meta_value |
    +———+——————–+————+
    | 702 | rmp_vote_count | 3 |
    | 702 | rmp_rating_val_sum | 12 |
    | 702 | rmp_avg_rating | 4 |
    | 712 | rmp_vote_count | 1 |
    | 712 | rmp_rating_val_sum | 3 |
    | 712 | rmp_avg_rating | 3 |
    | 742 | rmp_vote_count | 2 |
    | 742 | rmp_rating_val_sum | 7 |
    | 742 | rmp_avg_rating | 3.5 |
    | 746 | rmp_vote_count | 5 |
    | 746 | rmp_rating_val_sum | 19 |
    | 746 | rmp_avg_rating | 3.8 |
    | 755 | rmp_vote_count | 1 |
    | 755 | rmp_rating_val_sum | 4 |
    | 755 | rmp_avg_rating | 4 |
    | 768 | rmp_vote_count | 8 |
    | 768 | rmp_rating_val_sum | 37 |
    | 768 | rmp_avg_rating | 4.6 |
    | 772 | rmp_vote_count | 1 |
    | 772 | rmp_rating_val_sum | 5 |
    | 772 | rmp_avg_rating | 5 |
    | 784 | rmp_vote_count | 2 |
    | 784 | rmp_rating_val_sum | 6 |
    | 784 | rmp_avg_rating | 3 |
    | 792 | rmp_vote_count | 1 |
    | 792 | rmp_rating_val_sum | 3 |
    | 792 | rmp_avg_rating | 3 |
    | 803 | rmp_vote_count | 3 |
    | 803 | rmp_rating_val_sum | 15 |
    | 803 | rmp_avg_rating | 5 |
    | 808 | rmp_vote_count | 1 |
    | 808 | rmp_rating_val_sum | 3 |
    | 808 | rmp_avg_rating | 3 |
    | 829 | rmp_vote_count | 9 |
    | 829 | rmp_rating_val_sum | 40 |
    | 829 | rmp_avg_rating | 4.4 |
    | 835 | rmp_vote_count | 1 |
    | 835 | rmp_rating_val_sum | 4 |
    | 835 | rmp_avg_rating | 4 |
    | 839 | rmp_vote_count | 9 |
    | 839 | rmp_rating_val_sum | 40 |
    | 839 | rmp_avg_rating | 4.4 |
    +———+——————–+————+
    42 rows in set (0.00 sec)`
    `
    posts #742, 746 and 702 are returned but I also expect to see posts 839, 829 and 803, for example.

    I don’t know if my function is wrong, if I’m misunderstanding how this plugin interprets votes and ratings or there’s a bug. I can probably work out how to pull the data from the postmeta table within WordPress myself, but hoping there’s an easy solution here.

    Thanks.

  • The topic ‘Displaying top x top-rated posts’ is closed to new replies.