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);

ajax for visitors wordpress

You also need to add your action callback to non-privileged users. It works the same way as you registered your my_action_callback – you just need to add another line. add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); add_action( ‘wp_ajax_nopriv_my_action’, ‘my_action_callback’ ); Notice the wp_ajax_nopriv_ in front of your action – this tells WordPress that any user may call this … Read more