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

enter image description here

  • Are these users logged in or visitors? If they're logged in you can track by user ID if they're not then all you have to go on is IP ( which is flimsy at best )
    – Howdy_McGee
    Feb 1, 2019 at 3:43
  • for now i am using IP address to restrict. Feb 1, 2019 at 10:48


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.