How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)

first of all at the end of using a new WP_Query it’s good pratice to always use wp_reset_postdata(); to be sure nothing had compromise your database. $already_reserved = new WP_Query(array( ‘post_type’ => ‘appointments’, ‘fields’ => ‘ids’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘datetime’, ‘value’ => $date_time, // timestamps ‘type’ => ‘numeric’, ‘compare’ … Read more

Why Ajax Doesn’t Work?

You should move this code into a new plugin instead, e.g. save this file as wp-content/plugins/example-ajax-handler.php <?php /* Plugin Name: Example AJAX handler Description: Handle example_ajax_request admin-ajax requests Version: 0.0.1 */ add_action( ‘wp_ajax_example_ajax_request’, ‘example_ajax_request’ ); add_action( ‘wp_ajax_nopriv_example_ajax_request’, ‘example_ajax_request’ ); function example_ajax_request() { if ( isset( $_REQUEST ) ) { $postID = $_REQUEST[‘postID’]; print $postID; } … Read more