I'm developing WP plugin which when user enters ID
will get post against that ID
. It is working fine on admin side. I've followed this example to get data by AJAX call but now I'm trying to do it on the front end where anyone can enter ID
and get a result. I've removed function which I was using to create page on admin side. Now I have 3 functions named:
- hello_word()
- ajax_script()
- ajax_handler()
I've tried to use following hooks to register but it was not working
- add_action( 'admin_footer', 'ajax_script' );
- add_action( 'wp_ajax_my_action', 'ajax_script' );
- add_action( 'wp_ajax_nopriv_my_action', 'ajax_script' );
hello_word()
function contains code for text field and button.
I call hello_word()
function from a template file and it's being displayed correctly, but AJAX is not working when I click button. The issue I found is that ajax_script()
is not loaded and in debugging mode in source there is nothing when I click button.
So how to load ajax function correctly, while I'm calling hello_word()
from a template file?