How to sort a loop after most viewed

Having taken a quick look at the wp-postviews documentation, it seems you can change query_posts( ‘posts_per_page=5’ ); to query_posts( ‘posts_per_page=5&v_sortby=views&v_orderby=desc’ );, but I haven’t tested that. Give it a shot and see how it turns out. A cautionary note on doing this: What often happens when you sort by views is that the first page … Read more

sort posts by getPostViews in functions.php

You can use what you currently have and add a new condition: function sorter($wp_query) { if(mysql_real_escape_string($_REQUEST[“sorting”]) == “date”){ usort($wp_query->posts, ‘cmp_date’); }elseif(mysql_real_escape_string($_REQUEST[“sorting”]) == “title”){ usort($wp_query->posts, ‘cmp_alpha’); }elseif(mysql_real_escape_string($_REQUEST[“sorting”]) == “views”){ //create a list of all post ids as an array $ids = array(); foreach ($wp_query->posts as $p) { $ids[] = $p->ID; } //the query these posts again … Read more

Post Views Code Hacks

// Post views 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”; } if ($count == ‘1’) { return $count.’ View’; } else { $count = number_format((int)$count); return $count.’ Views’; } } function setPostViews($postID) { $count_key = ‘post_views_count’; $count = get_post_meta($postID, $count_key, true); if($count==”){ $count … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)