Skip Navigation

[Resolved] Voting for Items and sort them

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by JensP9777 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1334235

Hey guys,

is there a way to build a voting feature in toolset that can be used in the filter?

What I want to do:
- Each user can vote (once, cookie restriction possible?) for a item
- Theres a field that shows the number of votes
- Just voting wont change the order
- Theres a filter when you can order for the most popular items

Is that something that can be done with toolset? 🙂

Cheers
Jens

#1334469

Hi, I think it's possible but it would require a bit of custom code. It is not currently possible to sort a View by the number of related posts in a Types post relationship. In order to sort a View of some posts by a number of votes, you would have to include the number of votes in that post type as a custom field. To modify this value on the front-end of the site, you would have to use a Form that edits this post. The Form would simply have a submit button that says something like "Add my Vote". When the Form is submitted, you would use custom code and the Forms API cred_save_data to get the current number of votes and increment it by one, then save that new value. This part requires PHP. Next, you would have to set up some kind of conditional to prevent Users from submitting the Form more than once. One way you could do that is to create a repeating number field on the User profile, where you store the numeric ID of each post the User has already voted for. In the same cred_save_data hook, you could update that custom field value using the ID of the post being edited. The conditional would check to see if the current post ID already exists in the User's custom field. If so, you would not display the edit post Form for voting.

If you want to allow the User to un-vote, that's another level of complexity to consider. Check out these other tickets about Favorites, which includes a similar setup:
https://toolset.com/forums/topic/favorites-view-conditional-button-on-post-add-to-remove-from-favorite-list/
https://toolset.com/forums/topic/favorites-view/
https://toolset.com/forums/topic/favorite-posts-by-logged-in-user-add-to-remove-not-working-properly/

Those examples don't require incrementing or decrementing the vote count, and even without that you can see it's a fairly complex feature to implement. So I would consider other 3rd-party voting plugins as well, and determine which makes the most sense for your project and skill level. Let me know if you have additional questions about this.

#1334509

Hey Chris,

thanks for your nice answer, even on a sunday! 🙂

To be honest, this extend my skills. Can you recommend any 3rd party plugin that would work with toolset? Do you know any? 🙂

Cheers
Jens

#1334585

I don't know of any integrations between a voting plugin and Toolset, unfortunately, so I don't have any solid recommendations. I searched the forums for "voting", and another User had some luck with this one: https://wordpress.org/plugins/thumbs-rating/
However, their project was in 2017 so I don't know if that is still relevant:
https://toolset.com/forums/topic/user-upvotes-of-posts/
If a plugin isn't working as expected, I'll be glad to take a closer look.

#1334743

Thanks Chris! Ill check out your links and see if I can get it done somehow 🙂

Cheers
Jens