Jump to content
Sign in to follow this  

Modifying code for Buddypress community

Recommended Posts

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?



Share this post

Link to post
Share on other sites



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'))

	$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";
	} 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;

Perhaps i just need a bit of code to refresh the $votes count?

Share this post

Link to post
Share on other sites

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 by QuickOldCar

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

@QuickOldCar, by refresh, I think he means the vote count is reset every day back to 0.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.