Jump to content

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?



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?

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
Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.