Vote it Up – Post Order
-
This is a method of ordering your posts by vote count, if you have the ‘Vote it Up’ plugin for WordPress. It’s based on another script I found somewhere else in the forum – but much improved I feel.
Place this function inside your votingfunctions.php, located at ‘wp-content/plugins/vote-it-up/’, you can pass any “post-filtering” query to it:
function ShowPostByVotes($query) { global $wpdb, $voteiu_databasetable; $upperlimit = get_option('voteiu_limit'); if ($upperlimit == '') { $upperlimit = 100; } $lowerlimit = 0; $votesarray = array(); $pageposts = $wpdb->get_results($query, OBJECT); $query_limited = $query." LIMIT ".$lowerlimit.", ".$upperlimit; $posttablecontents = mysql_query( $query_limited ); while ($row = mysql_fetch_array($posttablecontents)) { $post_id = $row['ID']; $vote_array = GetVotes($post_id, "array"); array_push($votesarray, array(GetVotes($post_id))); } array_multisort($votesarray, SORT_DESC, $pageposts); $output = $pageposts; return $output; }
Then create a new loop like this:
// Example of a query you could use $query = " SELECT wposts.* FROM wp_posts wposts, wp_postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'yourkey' AND wpostmeta.meta_value = 'yourvalue' AND wposts.post_status = 'publish' AND wposts.post_type = 'yourtype' ORDER BY wposts.post_date DESC "; // This is the loop $pageposts = ShowPostByVotes($query); if ($pageposts): foreach ($pageposts as $post): setup_postdata($post); // loop content goes here include 'yourloopcontent.php'; endforeach; endif;
Hope that helps some people, I know a few were having the same problem as me!
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Vote it Up – Post Order’ is closed to new replies.