0

How can I view my posts in ascending order by number of views?

This is just for internal use so I can see how different posts are performing. Currently if I go to posts in the dashboard I can only filter by date. With over 900 posts I want to be able to see them in order by number of views. Views is a field there but I can't sort by it.

2
0

Use the following snippet to track post views on your wordpress blog. The first thing you want to do is add this snippet to the functions.php of your wordpress theme. Follow step 1. and step 2. to track and display the number of views for each post. Credits to the author here on this post

http://wpsnipp.com/index.php/cache/track-post-views-without-a-plugin-using-post-meta/

function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, '0');
    return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
    $count = 0;
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, '0');
}else{
    $count++;
    update_post_meta($postID, $count_key, $count);
}
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
0

i made this for u and i t works well ! you have to change download_counter to any post meta you have!

$popularpost = new WP_Query( array( 'meta_key' => 'download_counter', 'orderby' => 'meta_value_num', 'order' => 'DESC' ,'paged' => get_query_var( 'page' ) ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
global $post;

/// loop here

endwhile;
0

Use the post metadata for download counter and then use this query to get your required data

 $loop = new WP_Query( array( 
                           'meta_key' => 'download_counter', 
                           'orderby' => 'meta_value_num', 
                           'order' => 'ACS'
                     ) );
while ( $loop->have_posts() ) : $loop->the_post();

 the_title();
 .
 .
 .
 endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.