0

I am working on a Wordpress project where I have movies, books and games as custom post types. Any logged in user can add stars(review points) to each of the CPTs.

My way of implementing this was create new CPT called review. When user clicks on star to add review points to certaint CPT it creates new post with type review which in itself has meta fields review_post_id(which holds ID of post(movie,book,game) user is adding review points to) and review_score(which holds score user has selected (1-5 points)).

To show avg review score I just loop through all reviews which have review_post_id of ceratin post and then sum them and divide by number of reviews. Since reviews are custom post types I can show each user his own review score.

Now, mainly I am asking this question to see if this is correct way to do this(since same principal can be used for many other use cases) and also because of more experinced developer told me that I should have not created new CPT (review) and should use post_meta table of Wordpress.

But I don't think this is possible to overcome using wp_posts_meta, since this is many-to-many relationship and users and posts are one-to-many relationship.

Any suggestion is appreciated.

Thanks in advance and happy new year!

EDIT: I found that custom comment type can be used which links user to certain post, this could be the solution as this relationship is clearly many-to-many and I could store review_score(points) in comments meta table. Just want to hear your opinion on what is the best way to do this.

2 Answers 2

0

As you're in the WP ecosystem, use it. There are already lots of plugins doing "review system" https://wordpress.org/plugins/search/reviews/

Find one which match the best your need and then improve it thanks to the filters and actions you can find in the plugin chosen.

--Edit-- If you do not want to use a plugin. I think a CPT is needed only if you want in your review a note + a review. If you only need a note (1 to 5) then a post meta updated with the number of stars clicked (note given) should do the trick.

2
  • Thanks for the answer. But what if I wasn't going to use any plugins, what would be the thought process, it is more important to me than just solving the problem. Jan 5, 2022 at 8:41
  • Alright, but in this way I will not be able to show user the review he gave only the final number all people gave to specific type. Jan 5, 2022 at 12:24
0

In the end I used comments table with type of review which holds user_id of which user has actually clicked on stars(gave review) and post_id which holds on which post(movie, book, game) he is reviewing. Then for the points given (1-5 stars) I just use comments meta to store this.

This gives me flexibility to show each user number of starts they gave and also average number of all stars given to specific post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.