I want rating system like on wordpress’s official site.
Every user while making review can rate post (2)
and the total rating is displayed near the post (1).
Looks pretty simple but all plugins which I found by now
either show only total rating or allow to rate comments of users or to
do whatever else but not these.
Any help is appreciated because I got lost in plugins and think of writing by myself this functionality from scratch.
1 Answer
While there are a lot of plugins that adds rating type of stars, I would suggest that you code your own. Mainly because most of these are very feature rich with things you will not need.
This is a relatively simple process:
-
Add a custom user metadata using
update_user_meta()
, name itposts_voted
. -
Add a custom post meta value using
update_post_meta()
. The string value will be the rating, for example,4.5
. Name itpost_rating
. -
Then add rating stars to your single.php using
wp_star_rating()
. -
When user selects their rating, you should update the user’s
post_voted
value and store the post’s ID in the array, and then you should use their choice of rating and add a simple algorithm for thepost_rating
value. -
Finally, on loading the page, do a check if the user’s
posts_voted
contains the ID of the post; if it does, disable the voting for this user.
Doesn’t this sound a lot better than adding a random plugin that contains tons of unnecessary features?