Add Ajax Hooks and Call from Custom Template PHP

may be here is the error add_action( ‘wp_ajax_my_ajax_action’, ‘my_ajax_action_callback’ ); add_action( ‘wp_ajax_nopriv_my_ajax_action’, ‘my_ajax_action_callback’ ); change to add_action( ‘wp_ajax_my_ajax_action_callback’, ‘my_ajax_action_callback’ ); add_action(‘wp_ajax_nopriv_my_ajax_action_callback’,’my_ajax_action_callback’ ); and in ajax change: action : ‘my_ajax_action_callback go to functions.php and add: require(dirname(__FILE__) . ‘/custom_template.php’); make sure your ajax url is correct!!

Getting 400 Bad Request on AJAX Call

I believe the problem is here: // handle AJAX calls for both logged in and guest users add_action(‘wp_action_websites_cpt_create_post’, [$this, ‘create_post’]); add_action(‘wp_action_nopriv_websites_cpt_create_post’, [$this, ‘create_post’]); Because the format should be: add_action( ‘wp_ajax_{ACTION_NAME}’, [ $this, ‘create_post’ ] ); add_action( ‘wp_ajax_nopriv_{ACTION_NAME}’, [ $this, ‘create_post’ ] ); ..where {ACTION_NAME} is the “action” name, e.g. websites_cpt_create_post. See wp_ajax_{$_REQUEST[‘action’]} and wp_ajax_nopriv_{$_REQUEST[‘action’]}.

WordPress is Not Setting PHP $_POST on Custom Ajax

I’m having some doubts about your code. IF your using WordPress you should use https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action) So you no session.php, but a function: add_action( ‘wp_ajax_foobar’, ‘my_ajax_foobar_handler’ ); function my_ajax_foobar_handler() { $u = $_POST[“url”]; $p = $_POST[“product”]; echo $u . ” ” .$p ; wp_die(); } and simplify yours JS jQuery.post( my_foobar_client.ajaxurl, { ‘action’: ‘foobar’, ‘url’ : … Read more

Unset session variable on page reload / setup but exclude AJAX

Try using wp_doing_ajax() like so: function unset_filter_session() { if ( ! wp_doing_ajax() ) { //Reset sessions on refresh page unset( $_SESSION[‘expenditure_filter’] ); } } UPDATE You can check the answer’s revision for this update part.. UPDATE #2 Sorry, I didn’t realize that you’re loading a page fragment (#content-area) using the jQuery.load() method. Or that you’re … Read more