Search function – problem with whole words

Exact means exactly that – the whole field must match, not just a word in the field. To get whole words that are part of the field, remove ‘exact’ => 1 Add this if ($_POST[‘terms’]) { $keyword = sanitize_text_field( $context[‘terms’] ); $keyword = ‘[[:<:]]’ . $keyword . ‘[[:>:]]’; $context[‘posts’] = Timber::get_posts(array( // other params here … Read more

do_action won’t work in ajax callback

Note: OP and me resolved the question/issue via chat — and despite the actual problem source is not known for sure, in the actual AJAX callback used by OP, there was actually no (or maybe OP had forgotten to make the) do_action() call. 🙂 Original Revised Answer (for reference): If you have something like so … Read more

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