- 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)
- Most efficient way to add javascript file to specific post and/or pages?
- 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?
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Security – Ajax and Nonce use [closed]
- Jquery ajax to custom php file: returning blank data
- Looking for a better way to handle an ajax script that pulls in post data on click
- Targeting single page with JS
- Can’t use get_results() in ajax query
- Use ajax to update_post_meta
- Problem with WordPress Ajax form
- Accessing an API with jQuery and AJAX
- Execute Jquery when a specific page in my plugin is loading
- what does $options = get_option(‘test_theme’); do?
- 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
- Validating an email input from form field before submit using JQuery, AJAX, and PHP
- Why does PHP called with Jquery AJAX not allow additional php code to be added?
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Database entry removed on browser refresh, Ajax PHP jQuery
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- 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
- How do I call a value from the datase using ajax
- 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
- Where to add my PHP codes for AJAX Jquery to work?
- How to pass values from one function to the other using an array variable
- How to change PHP variables with AJAX request in WordPress
- How to use wp_ajax_set_post_thumbnail?
- Update $wpdb query with AJAX
- Can’t make lazy load for my site, help!
- How to reload a php script, using AJAX and jQuery
- 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)
- wp_set_object_terms returns 500 error when called through AJAX function
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- 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)
- Remove item from post_meta array via AJAX
- number of posts with “Load More”
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- 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?
- Submitting my form to the database and then redirecting to payment site
- 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)
- Dynamic Gallery
- 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
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- notify users when changed database
- getJSON response to PHP
- ajax problems on loading page [closed]
- Upload multiple files via ajax from an HTML file input
- Help with AJAX request
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- custom AJAX filtering logic and outputting results into an Elementor Loop Grid widget
- Help with uploading file with AJAX and PHP
- Help with creating commenting system using PHP, jQuery and AJAX
- Update shortcode values using ajax call
- ajax select parent show child in another select and show posts in another select-ajax filter search
- Add/Remove User Meta Array via AJAX
- How do I ensure that the URL parameters are updated correctly when multiple filters are applied
- Filtered queries not responeding to page path