- WordPress loads jQuery in NoConflict mode. Do not use
$
. Use
jQuery
or one of the other solutions in the Codex. - If that Javascript is in a
.js
file, that is not going to work.
You cannot runPHP
in a Javascript file like that, without
reconfiguring the server, and the call toget_the_ID
would likely
fail anyway. - You are directly loading a
.php
file. That means that WordPress is
not being loaded so any attempt to use a WordPress function will not
work.
Item #1 and #3 are definitely problems. Item #2 may or may not be.
You should be using the AJAX API for this. Your WordPress functions will be loaded and will work correctly. The examples on the AJAX API Codex page are pretty straightforward. It should not be hard to translate your code to that pattern, but if you have trouble I will edit the answer when I have time.
Related Posts:
- Add a counter for mouseovers (custom field)
- How can I fetch loop of post titles via AJAX?
- Retrieve POST data from AJAX call
- Do I require the use of nonce?
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- How to use wp_localize_script in a WordPress page other than functions.php?
- Security – Ajax and Nonce use [closed]
- Targeting single page with JS
- Use ajax to update_post_meta
- Click loads template via ajax
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- WooCommerce: update custom fields after checkout validation failure
- 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
- 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 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”
- Ajax load more posts with multiple tax query
- WordPress Sending data to Ajax with select option
- 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?
- populate form fields in a loop with ajax
- 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?
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Add / Update Custom Fields After Select Pictures in Media Window
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- How to disable controls in theme customizer?
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- Pull GetOption() variable into jQuery dynamically created html
- Function won’t run onclick using Ajax
- WordPress plugin admin page – using WordPress function in linked php file
- A $_POST should occur when submit form but is not?
- jQuery Ajax PHP function call returning [object Object]
- Shortcode to pull posts
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Get uploaded image and attach it to the new post
- Admin-ajax php not working on new wordpress version
- Proper way to use WordPress function with AJAX PHP file
- Live search from database table
- Accessing an API with jQuery and AJAX
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- How to set variables with AJAX request to use in another function in WordPress
- Search Ajax Call – Use Form Data in Response
- Why does PHP called with Jquery AJAX not allow additional php code to be added?
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Database entry removed on browser refresh, Ajax PHP jQuery
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Display custom field value in woocommerce variable product via jQurey
- Ajax result show in console if is called outside function and not showing in array
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- How to change PHP variables with AJAX request in WordPress
- Update $wpdb query with AJAX
- Can’t make lazy load for my site, help!
- wp_ajax_ 400 Bad Request
- AJAX to add to cart multiple products woocommerce
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- WordPress ajax filter returning all posts when it should be filtering by category
- Input field duplicates on form submit by jQuery
- 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?
- Custom theme admin-ajax.php 400 (Bad Request)
- number of posts with “Load More”
- Find the method which AJAX GET calls
- AJAX Filter WHILE Loop not working WordPress
- WordPress AJAX load post metadata in modal
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- ajax form with multiple submit buttons and values
- How to run ajax in WordPress Post?
- Adding instant search to wordpress page
- Add php function into .js file (for tinyMCE button)
- Dynamic Gallery
- ajax form function error
- Load Meta box value into div AJAX [duplicate]
- Jquery autosave text area after typing
- notify users when changed database
- getJSON response to PHP
- Upload multiple files via ajax from an HTML file input