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
- Fatal error: Call to undefined function mysql_connect()
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- Custom Meta Field – Youtube embed
- Targeting single page with JS
- Insert post without actions/hooks
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- Import 10,000 Users into WordPress WITH a specific ID for each user
- How to convert objects into arrays
- Can’t get wp_insert_post to work
- Randomly Assign an Image’s Alt Text Based on Data From Post
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- Firing schema via code in functions.php doesn’t work
- How to get original custom taxonomy slug after the slug has been rewritten?
- Are nonces in WP REST API optional by default?
- How do I Import / Upload Files with jQuery AJAX?
- wp ajax return 0
- WordPress plugin: render only page content using ajax call
- Function won’t run onclick using Ajax
- email alert for product availability
- How to show meta value code HTML after x paragraph
- How do I prepare strings for insertions as values into a MySQL table?
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- How to get post category list as select in front-end?
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- AJAX function running TWICE with WordPress admin-ajax.php
- Updating Metadata with Shortcode
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- call to undefined function mysql_connect
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Setting up a cron job to auto update a custom field
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- WordPress is setting from header wrongly in wp_mail
- How to edit content in WordPress and the Polylang – plugin? – with demosite
- Trying to retrieve meta values from three different meta keys and display in rows
- ajaxurl usage for a custom function
- get_post_meta with variable
- Run insert if no entry otherwise run update with ajax
- WordPress upload images not displaying
- change attachment custom field onChange event
- Adding instant search to wordpress page
- How to exclude post from being queried based on custom meta value
- MySQL database migration to WordPress
- Search result page – display values from the result’s metaboxes
- Query Concatenation
- Display total count of products in orders of a specific order status
- Convert custom field date format to “WordPress default”