I think your problem is here:
$like_the_post = intval( $_POST['like_the_post'] );
You’re relying on the user’s browser’s POST input to determine whether to increment or decrement the count. When a user quickly clicks the button, the AJAX call hasn’t yet completed and changed the form input from true to false (or whatever’s vice-versa). Additionally, this approach is liable to being spammed by a script repeatedly hitting your AJAX script with this value set to ‘true’ to artificially inflate the ‘likes’ on a post.
Since it looks like you’re tracking the user_id when someone clicks the button, I’d suggest changing your AJAX code so that you first check to see if the user already has a record for that post_id – if not, increment the counter, if so decrement.
Related Posts:
- Refresh page after update_post_meta
- Access/update database with jQuery
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Database entry removed on browser refresh, Ajax PHP jQuery
- getting the values of hidden inputs to use them in a php mysql query
- notify users when changed database
- How to return number of found rows from SELECT query
- How to correctly add Javascript in functions.php
- Combine CSS and JS files from plugins
- How to export/import theme customizer settings?
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- WP API V2 returning Invalid User ID
- Export User Info to CSV from Front End
- Security – Ajax and Nonce use [closed]
- Nice scroll to wordpress
- error importing localhost export file to server
- How do I add a php statement to a jQuery string
- Looking for a better way to handle an ajax script that pulls in post data on click
- WPDB: how to get the value of a field in a custom database table
- Can’t use get_results() in ajax query
- Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- Passing jQuery value using Ajax to a page template
- ajax_object is not defined when ajax calls the function
- Why is this Ajax not working?
- Add custom php database code above
- wp_insert_post not working
- Use ajax from function.php
- Ajax return code 400
- combine Code 1 with Code 2
- database interactions using OOP
- Storing Array from returned database query and using the array in a new query
- WordPress not reflecting changed of the database
- ajax, right way to do it and make it works?
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Execute long and heavy processes
- Menu jumping when calling it via PHP
- Setting value of session with Ajax not working
- Click a radio button must set textfield value
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- db converts decimal number wrong
- Ajax contact form return 0
- AJAX – Returning Two JSON Objects with One PHP Function
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress Ajax Always returning 0
- Jquery window.send_to_editor function
- Should I use WordPress to skin a database website?
- Theme not calling Jquery properly
- Creating Database Table vs. Adding MetaData to Post & User
- How to add drag and drop functionalities to a div inside option panel
- How to make jquery count down timer function manually editable
- My jQuery Ajax form submit is still refreshing page?
- Cant connect to database with php 7.3
- Output votes to div dynamically in wordpress
- jQuery accordion menu
- Angular not defined [closed]
- Removed jQuery script from header.php , any problems?
- Set cookie for visitor
- Covert WordPress Blogname into JQuery
- Adding wp_list_categories to a specific div that was appended using jQuery
- Hot to check if new posts have been published since page load and notify online users?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- how can i include post meta in search result
- WooCommerce Query Product Titles
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- add role on WordPress in PHP on a second database
- Create a new account on site B with data from the purchase of site A
- How to search order using database frontend short code WordPress
- Replace jQuery with PHP or CSS for Customized WordPress wp_nav_menu
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- Outputting post content to jQuery .html() string
- Unable to insert two value in two different columns (WordPress database)
- Retrieving and Displaying Data From a Table
- why not selecting multiple rows of same standard_id using SQL query from database?
- Implement jQuery Smart wizard
- Woocommerce – if selected attribute term equals
- WordPress Slick Slider + Magnific Popup
- Using wp_editor() when not logged stopped working
- Show the subcategory name based on current product
- How to call WordPress PHP file using external js file
- Creating Log-In Page for backend server
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Front end/Database connection in WP
- WordPress 404 when using AJAX to call php function
- can’t delete a row from post_meta table
- how use php query in AJAX jquery
- jQuery doesn’t work in my php snippet
- Submitting my form to the database and then redirecting to payment site
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- Combining fancybox with multiple thumbnail plugin
- Highlight posts currently being edited on multiple editor site?
- Fatal error: Uncaught Error: Call to undefined function wp_nav_menu()
- Create an unique ID number after submit form
- Add specific phrase after every product title including the discounted price? [closed]
- Adding Custom JQuery Menu Fresh Slide Out
- How to get the last date updated of postmeta?
- Putting form result in my database