WordPress Ajax – looping data into a table

Have you actually added this action through functions.php? This might be of interest for you: https://developer.wordpress.org/reference/hooks/wp_ajax_action/ in your case the php function needs to be added as a hook: add_action(‘wp_ajax_fetch_data’, ‘DisplayInfo’) add_action(‘wp_ajax_nopriv_fetch_data’, ‘DisplayInfo’)

Call pre_get_posts inside ajax

Not the way you’re doing it, no. When the pre_get_post action is run any WP_Query queries run will be modified by the callback. Actions are not persistent, so when you run add_action() inside an AJAX callback that action is only going to be applied for that request, and you’re not running any queries in the … Read more

PHP cookie not set within AJAX call

Apparently I was missing the time() attribute. So when adding this to the expire option in the setCookie function, the cookie is being set. Code: setcookie(‘user-zipcode’, $zipcode, time() + MONTH_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN); setcookie(‘delivery-today’, $cookieVal, time() + DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN);

WordPress wp_localize_script nonce and ajax URL

wp_localize_script() doesn’t care much which script handle you use as long as it is a valid one. You could use your theme’s or Elementor’s main script handle with the function to make the data available for your script. You’ll need to check your theme’s or Elementors source coude to find what these handles are. Side … Read more