I’m trying to get the first 10 posts based on page views through WordPress Stats (now called Jetpack).
I managed to get this code to work (approximately..) after digging for hours over the forums (because variables and code changed from time to time):
<?php
if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv( 'postviews', "days=10&limit=10")) {
echo '<ol class="most-viewed">';
foreach ( $top_posts as $post ) {
if($post['post_id'] && get_post($post['post_id']))
echo '<li><a href="' . get_permalink( $post['post_id'] ) . '">' .
get_the_title( $post['post_id'] ) . '</a> (' . number_format_i18n( $post['views']) .' visits)</li>';
}
echo '</ol>';
}
?>
Now I’d like to exclude pages from this list and only have posts. The problem is that the WordPress.com Stats API does not offer a post_type filter. I should put somewhere this
if ( !isset($post->post_type) || $post->post_type != 'post' )
can you help me pointing out where should I add it?
Thanks in advance! 😀
Check for the post type with the post ID: