That will not work because you are referring to a single php file, instead the the whole WordPress environment.
There’s a easier way to use ajax in WordPress.
Use admin_url('admin-ajax')
as the form action, then put the function that will answer the ajax call in the theme’s functions.php.
More detail here in this answer
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- How to display multiple Post meta_key/meta_values by SQL query
- How to use multiple query with same meta key
- simple wordpress ajax plugin not working when not logged in
- Jquery ajax to custom php file: returning blank data
- Update WordPress Custom Field with AJAX on cached page
- How can update custom meta for all posts
- Is the regular ajax request method safe or I should use admin-ajax.php?
- AJAX in WordPress, sending coords data to MySQL and show after into map
- WooCommerce: update custom fields after checkout validation failure
- how to increase custom post value by one most efficiently?
- Ajax $wpdb not returning table data
- Checking for new message using AJAX and PHP. Server overload?
- How can I create a list of page titles from custom meta values?
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Refresh table data with Ajax
- Is it possible to retrieve all posts with a certain value for metadata?
- Non-Closing PHP Query in WordPress Loop
- how to get serialized post meta
- WordPress loop by meta key that is an array? and how loop multiple arrays
- A $_POST should occur when submit form but is not?
- How to store multiple custom meta box
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- How to use AJAX in WordPress in MYSQL query?
- Order a WP_Query by meta value where the value is an array
- Live search from database table
- Processing ajax call to php to insert into mysql database
- Add a custom class to the body tag using custom fields
- Define category ID using get_post_meta
- Add a counter for mouseovers (custom field)
- Hide a div when a custom field is empty
- WordPress stripping out custom field tags
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- How to update custom fields when post is published?
- What is the correct way to search 3 custom fields only in WordPress?
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- autocomplete in wordpress using ajax with json-data
- WP post meta – for loop inside for loop
- Remove item from post_meta array via AJAX
- When working with a post, almost all wp_postmeta are deleted
- Updating Lat and Lng of posts automatically gives sporadic results
- Prepared DB Query from _POST array
- Ajax not updating to database
- WordPress AJAX load post metadata in modal
- Include a custom field in mysql query
- MySQL query in WordPress with AJAX
- retrieve wordpress post-meta using php not wordpress functions
- If custom field doesn’t exist, or exists and it’s true show title?
- Metadata on the WP_Post object
- Help with creating commenting system using PHP, jQuery and AJAX
- Trying to GET data with ajax from database and show in fullcalendar
- MySQL Query that looks for post with Custom Field, then changes Category
- How to run JS, PHP and etc. inside WP post?
- Why is variable not working on custom sql query using wpdb?
- Trying to implement Ajax comments in WordPress, getting WP error
- How to test nonce with AJAX – Plugin development
- Can’t search posts using WP_QUERY inside AJAX Function
- Show MySQL errors that occur when I excute $wpdb->insert()
- Woocommerce add to cart quantity buttons with AJAX
- Importing hard coded custom field into acf field
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- class click counter save number
- Get WooCommerce product details and transfer them to a custom DB table
- Random order of WP_Query results with highest meta value
- tracking number field in Woocommerce order [closed]
- Any possible way to make $wpdb->get_results() return anything else than array?
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Remove one value in dismissed_wp_pointers?
- get post based on category chosen in drop down – The ajax method
- Why is $_REQUEST an empty array in admin-ajax.php?
- WordPress Site Running Extremely Slow on Dedicated Server
- How can I export posts with featured images, without download them
- AJAX request status 200 but no actual “response”
- get current custom post ID by WP_Query method
- How to make drop down post title
- Ajax not working es expected (Returns 0)
- Create onClick Event to Re-load a Widget
- How to securely provide a $_POST var in WP_Query with PHP 7?
- The text box have space character
- how to remove metadata from the posts of my blog?
- Can’t get wp_insert_post to work
- Load a page into a div with Ajax
- Trying to remove post thumbnail with plugin
- Creating a Multi-Level Associative Object Using AJAX
- Accessing data from a non-WP database/table within a page content
- Randomly Assign an Image’s Alt Text Based on Data From Post
- Create WP_Query to search for posts by their categories or their parent/child categories
- What is a valid parent for get_terms()?
- Passing the custom field values in the wp_get_current_user array function
- Get updated query results on page after insert in database
- WSoD being caused by this piece of code
- wordpress count link clicks by ip address
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- Sort posts by custom fields value using dropdown menu
- Ajax – Call to undefined function get_option()
- I want to select the from values from database in WordPress? [closed]