• Hey everyone,

    I write to this forum in the hope that some incredible genius can help me out.

    I need to make a custom poll based on images/buttons without using a plugin:
    1. A user enters my website
    2. User clicks on a post. The post has two images/buttons side by side.
    3. The user clicks an image/button and a counter is displayed (or already was displayed) below each image. This number is the amount of “votes” that the images have.
    4. This number of votes is stored in each post.

    As you can see, basically what I need is a click counter that counts how many times and image or button is clicked, acting as a poll. This is stored and all users can see it.

    I am a beginner with coding, yet I am willing to use it if proper guidance is provided. I also use Elementor Pro, ACF, ACF Frontend Forms, if it helps.

    Please if someone can help me, it would be appreciated.

    • This topic was modified 4 years, 7 months ago by Jan Dembowski.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Even if you write your own code, you still need a plugin to contain your code (or a child theme) The browser must send the user’s selection to the server, where your code can add the vote to the totals kept in post meta. The simplest way is to have the buttons be links which either reloads the page, or loads the next post. The link would include a query string telling your server side code what the vote was (and for which post if the link will lead to a new post)

    You could add the code to handle the vote tally right on the post’s template code. If you go this custom template route, you’re better off with using a child theme to contain your template and custom code.

    A more advanced approach would be to use Ajax techniques to tally the vote without needing to reload the page. Either way, you need a mechanism to prevent users from voting more than once. You could save what posts were voted on in a cookie, but users can easily cheat by using other browsers or deleting your site’s cookies. For better security, you’d need to require users to log in so the posts they voted on can be saved in their user meta.

Viewing 1 replies (of 1 total)
  • The topic ‘Poll based on Images/Buttons’ is closed to new replies.