database - how restrict user to give star ratings once for a post?

admin2025-06-03  3

I am creating a plugin where i want to restrict a user to do give ratings to the post but not more than once.

function frs_insert_ratings($content) {
if(!is_feed() && !is_home()) {

global $wpdb;
$tablename = $wpdb->prefix . "rating_calculator";

$content.= "<div class='rating'></div>";
global $post;
$postID = $post->ID;
$content.="<form method='post' action=''> <input type='hidden' id='post_id' value='".$postID."'/></form>";
$getarow = $wpdb->get_row( "SELECT * FROM $tablename WHERE post_id = $postID" );
if(!empty($getarow)){
$woke = $getarow->rating_count;

$total = ($woke*15)/100;
$content .= "<span id='woke'> ".$total."% Woke </span>";
}else {
$content .= "<span id='woke'> 0% Woke </span>";
}
}
return $content;
}

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748954480a315123.html

最新回复(0)