Track view count by adding following code under theme functions.php file
function post_grid_single_post_view_count(){ // replace by your post types if ( is_singular( 'post' )){ $post_id = get_the_ID(); $post_view_count = (int) get_post_meta(get_the_ID(),'post_view_count', true); update_post_meta(get_the_ID(), 'post_view_count', ($post_view_count+1)); /* * * for unique post view count * * $cookie_name = 'post_view_count'; * if(isset($_COOKIE[$cookie_name.'_'.$post_id])){ } else{ // Update +1 view count setcookie( $cookie_name.'_'.$post_id, $post_id, time() + (86400 * 30)); // 86400 = 1 day update_post_meta(get_the_ID(), 'post_view_count', ($post_view_count+1)); } * * */ } } add_action('wp_head','post_grid_single_post_view_count');
Then follow the options as mentioned on screenshot under Query Post tab.