When you load a php file directly via an ajax request (UncheckPackageThemeHelper.php
) it’s loaded outside the context of WordPress, so no WordPress core functions are available.
All WordPress ajax requests should be routed through admin-ajax.php
. You can print the URL with the function admin_url
:
admin_url( 'admin-ajax.php' )
When admin-ajax.php
is loaded, WordPress is bootstrapped, so you’ll now have access to core functions.
The last step is to pass an action
parameter from your javascript, and map that action to the function you want called when the action is executed:
add_action( 'wp_ajax_my_action', 'my_action_callback' );
Related Posts:
- populate form fields in a loop with ajax
- How to disable controls in theme customizer?
- How to change PHP variables with AJAX request in WordPress
- Custom theme admin-ajax.php 400 (Bad Request)
- How to speed up admin-ajax.php in wordpress
- Returning a value from a PHP page
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Sending jsPDF documents to the server
- Use ajax from function.php
- Ajax return code 400
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- doing an ajax request always outputs 0
- How to show a dynamic_sidebar if main content content’s height is > a set amount?
- How to test nonce with AJAX – Plugin development
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- Checking for new message using AJAX and PHP. Server overload?
- AJAX request status 200 but no actual “response”
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Load a page into a div with Ajax
- wordpress count link clicks by ip address
- ajax, right way to do it and make it works?
- Ajax load more posts with multiple tax query
- WordPress Sending data to Ajax with select option
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax date_query not working past the first iteration
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- AJAX pagination, update current page
- Save Search System
- adjust section according to country?
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- How to add a do_action on refreshing of WP customizer?
- Menu jumping when calling it via PHP
- Setting value of session with Ajax not working
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- WordPress admin-ajax.php 400 bad request
- WordPress Ajax Call inserting data but success response false
- Ajax contact form return 0
- AJAX – Returning Two JSON Objects with One PHP Function
- Pull GetOption() variable into jQuery dynamically created html
- Royalty-Free Sliders used in theme development
- Unset session variable on page reload / setup but exclude AJAX
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress Ajax Always returning 0
- Function won’t run onclick using Ajax
- Theme not calling Jquery properly
- How to keep track of when a vote is cast?
- WordPress plugin admin page – using WordPress function in linked php file
- How to echo a PHP code into WooCommerce variation product?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- How to call a function from functions.php with ajax?
- Remove item from post_meta array via AJAX
- number of posts with “Load More”
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Woocommerce variable products are being added to the card on the homepage (ajax)
- Find the method which AJAX GET calls
- AJAX Filter WHILE Loop not working WordPress
- Ajax not updating to database
- WordPress 404 when using AJAX to call php function
- wordpress ajax pagination
- WordPress AJAX load post metadata in modal
- how use php query in AJAX jquery
- Ajax Load more CPT via shortcode
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- wordpress ajax return 0
- Submitting my form to the database and then redirecting to payment site
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- Pass the updated value of aid from form using ajax
- ajax form with multiple submit buttons and values
- How to run ajax in WordPress Post?
- 500 (Internal Server Error) of external php file
- Use jQuery and AJAX to get HTML
- Adding instant search to wordpress page
- Add php function into .js file (for tinyMCE button)
- Image not displayed
- Dynamic Gallery
- Adding Media button to only pages
- best way to communicate between php and jquery/javascript
- Loading a post’s content, into a div outside the loop, when it’s title is selected in a list
- Fatal error: Uncaught Error: Call to undefined function wp_nav_menu()
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- Load Meta box value into div AJAX [duplicate]
- Jquery autosave text area after typing