Support

Account

Home Forums Backend Issues (wp-admin) Update value by 1 onclick

Helping

Update value by 1 onclick

  • I’ve reading documentations about it but I’m quite new with PHP. Basically what I want to do is that I want to make a like button for posts. I have made a custom field called ‘henkilon_saamat_aanet’ and I have set the default value to 0. Now I want to make a button that when it’s been clicked the ‘henkilon_saamat_aanet’ value increases by one. If it is not too much asked it would be more awesome if the button is been pressed again the value decreases by one.

    It would be great if someone would be that kind and make an example of it.

  • The topic is too complex for a simple explanation or providing simple code examples. The best I can do is to give you an outline of what would be needed.

    The first thing you’ll need to do is read about AJAX in WP, the best source of information in this is here https://codex.wordpress.org/AJAX_in_Plugins. You need to create AJAX what will make a request to update the value.

    If you want to be able to reduce the value you not only need to know how many times it was clicked, you will need to record who clicked it. This will involve the user’s profile keeping track of all the posts they’ve liked and if there is not a profile it will involve cookies or some other mechanism for knowing if the person viewing the page has already liked it or not. This will all depend on how the site is set up and how visitors use the site.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Update value by 1 onclick’ is closed to new replies.