WordPress.org

Ready to get started?Download WordPress

Forums

stats_get_csv retrieve just a few posts (not the one I set in "limit" parameter) (1 post)

  1. MultiformeIngegno
    Member
    Posted 1 year ago #

    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. :D

    Why doesn't it just pull always 10 posts?

    Thanks in advance!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by MultiformeIngegno
  • This topic is not resolved
  • WordPress version: 3.4.2