RoberJames Posted September 4, 2016 Share Posted September 4, 2016 Good day, I have a limited understanding of php. I have been working on creating a community using buddypress/wordpress for 6 months now. I have overcome very many obstacles. However there is one obstacle i have been stuck on for months now. My community would be similar to a link submission site. I want links posted to be voted on daily, i want the links ordered from most voted to least voted. I want the vote count to refresh every 24 hours. I found a solution here: http://bavotasan.com/2009/simple-voting-for-wordpress-with-php-and-jquery/ This solution works, but it does not refresh every 24 hours. As far as i can tell, all i need to do is add a simple code to vote.php or functions.php? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/302077-modifying-code-for-buddypress-community/ Share on other sites More sharing options...
RoberJames Posted September 4, 2016 Author Share Posted September 4, 2016 Update! Sorry, i have found a updated version of this. Here: http://bavotasan.com/2011/a-better-voting-system-for-wordpress/ The functions file looks like this: add_action("wp_ajax_add_votes_options", "add_votes_options"); add_action("wp_ajax_nopriv_add_votes_options", "add_votes_options"); function add_votes_options() { if (!wp_verify_nonce($_POST['nonce'], 'voting_nonce')) return; $postid = $_POST['postid']; $ip = $_POST['ip']; $voter_ips = get_post_meta($postid, "voter_ips", true); if(!empty($voter_ips) && in_array($ip, $voter_ips)) { echo "null"; die(0); } else { $voter_ips[] = $ip; update_post_meta($postid, "voter_ips", $voter_ips); } $current_votes = get_post_meta($postid, "votes", true); $new_votes = intval($current_votes) + 1; update_post_meta($postid, "votes", $new_votes); $return = $new_votes>1 ? $new_votes." votes" : $new_votes." vote"; echo $return; die(0); } Perhaps i just need a bit of code to refresh the $votes count? Quote Link to comment https://forums.phpfreaks.com/topic/302077-modifying-code-for-buddypress-community/#findComment-1537087 Share on other sites More sharing options...
QuickOldCar Posted September 5, 2016 Share Posted September 5, 2016 (edited) Is my understanding you want the totals for votes somewhere like the sidebar and to refresh every so often. Is no need to modify the current script have, that either adds a vote or not upon casting a vote via POST. You need to write a script to query and fetch all the results, can use a header or meta refresh and include or iframe the script in a sidebar text widget. I would think refreshing it more often be needed as well. Must be before any output at the beginning of the script. header( "refresh:30;url=script_name.php" ); Meta does not need to be at the beginning. <meta http-equiv="refresh" content="30;URL='http://site.com/script_name.php'" /> Edited September 5, 2016 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/302077-modifying-code-for-buddypress-community/#findComment-1537089 Share on other sites More sharing options...
QuickOldCar Posted September 5, 2016 Share Posted September 5, 2016 Pretty much you have to query the counts sorted in the order you desire. Then fetch the post_id's information for each so is something of value to show and possibly click on as well. Quote Link to comment https://forums.phpfreaks.com/topic/302077-modifying-code-for-buddypress-community/#findComment-1537090 Share on other sites More sharing options...
PaulRyan Posted September 5, 2016 Share Posted September 5, 2016 @QuickOldCar, by refresh, I think he means the vote count is reset every day back to 0. Quote Link to comment https://forums.phpfreaks.com/topic/302077-modifying-code-for-buddypress-community/#findComment-1537112 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.