• This code pulls the top viewed posts (via wordpress stats API). I can set how many posts to show and the days to “count”:

    <?php
            if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv( 'postviews', "days=60&limit=15")) {
            echo '<ol class="most-viewed">';
              foreach ( $top_posts as $post ) {
                if (
    			$post['post_id']
    			&& get_post( $post['post_id'] )
    			&& 'post' === get_post_type( $post['post_id'] )
    			)
                  echo '<li><a href="' . get_permalink( $post['post_id'] ) . '">' .
                      get_the_title( $post['post_id'] ) . '</a> (' . number_format_i18n( $post['views']) .' visite)</li>';
              }
              echo '</ol>';
            }
    ?>

    The strange thing is that if I set days=2&limit=10 I get 6 posts (instead of 10), if I set days=60&limit=10 I get 2 posts, if I set days=-1&limit=10 I get just 1 post!!! Why does this happen? 🙁 The blog has about 2000 articles so there are of course more than 10 posts. 😀

    Why doesn’t it just pull always 10 posts?

    Thanks in advance!

  • The topic ‘stats_get_csv retrieve just a few posts (not the one I set in "limit" parameter)’ is closed to new replies.