WordPress AJAX Call (Step-by-Step Guide)
HTML-код
- Опубликовано: 1 дек 2024
- Using AJAX with WordPress can be a bit daunting if you don’t know where to start.
The WordPress Codex is not much help. It assumes you already know everything about WordPress. :)
If you’re new to AJAX or if you are just trying to figure out how to use AJAX with WordPress, I gotcha covered!
In this step-by-step guide we will go over how to make a WordPress AJAX call, the WordPress AJAX hooks (wp_ajax and wp_ajax_nopriv), how to define the AJAX url (admin-ajax.php), and everything else you need know.
You'll be an WordPress AJAX Ninja in no time!
I also made a companion video on How to Make a Secure WordPress AJAX Call (with Nonces):
• How to Make a Secure A...
AJAX Tutorial Page & Example Files Download:
sharewebdesign...
Your guide is AMAZING !!! Thank you so much, this is the only video that explain clearly how to do that.
No problem. Super happy that the tutorial helped you! Thank you for the comment!!
You are going to heaven 🙏 Thank you very much!
I am glad this helped! Be sure to check out the follow up video on "How to Make a Secure AJAX Call in WordPress (with Nonces)" if you are going to be passing any kind of secure data.
Hi, i want to execute a shortcode (which yeilds a chart) when a button is pressed. how do i do it? i have been struggling for a couple of days now
You want the call back in your functions.php to send back your shortcode. Something like echo do_shortcode('[your_shortcode]');
please what is adding tei-ajax-post=1 to the end of my URL, i was able to discover it on google analytic
you helped me understand ajax after years of struggling
That's awesome! I am so happy this helped you. Thank you so much for the kind words. You made my day! :)
how to create a button that calls a custom ajax code for example when clicking that button, i want to call a wp rest api
very very very very helpful. keep going and uploading videos like these.
Like, commented and suscribed! Your work is awesome!
Thank you! You are awesomeness!
I did that but the ajax function call the short+code and retun the html, but not refresh the page, why? I need to do someething after call the shortcode function?, the shorcode have parameter and I call echodo_shortcode('[reneder_page cat="'. $valuebyparameterajax.'"]'), but not refresh the page, thanks
This sounds like you are asking about something outside of the this video tutorial. Is that correct?
well ok, this override banana with apple i can do with simple js, .........it would be much better to show how exactly you get something like post content on click or some post data... because i see your example of ajax but when thinking how to get some post data i'm stuck ...
It sounds like you are looking to do something outside of the scope of this tutorial. If you need some professional help please feel free to contact me via my website. Thank you!
subscribed, thankyou.
You are very welcome and thank you!!
where did you get the information in the functions.php before you pasted the code in it?
I created it. It's just a function to enqueue the style.css. Let me know if you want the code and I past it here.
@@shawnhayes yes I want the code
Can we use this for making the ajax call for ACF repeater fields?
Yes, you can. You can use it for any AJAX call in WordPress. You may want to serve the call from your plugin though instead of the functions.php in your theme.
Hi sir, can you help me fix my problem in importing template from starter template, Because I cant import template it says: " We could not start the import process due to failed AJAX request and this is the message from WordPress: Error: 0 error "
Are you asking a question about the tutorial or a problem you are having with your own web development project?
Thanks
You are very welcome! Thank you for the comment!!
you are amazing
Thank you! You are pretty amazing yourself my friend! :)
Download isn't working giving me a bad page 404
Sorry about that! I moved servers and the link didn't get updated. I just noticed your comment but it's been fixed for a while. Thank you for flagging this. Very much appreciated!
What about nonce ?
You can use wp_create_nonce() as a hidden field when using AJAX with WordPress. I think it may be a little out of scope for this tutorial, but definitely a great way to add security and check if the ajax request is coming from your website or not. I added a nonce version to the tutorial for more advance users. You can find that in the show notes.
Thank you so much.
You are very Welcome!
Thanks for this sir.
You are very welcome!
You are very welcome! Thank you for the comment.
can you do ajax with rest api?
Yes, I believe so.
Yes, you can! WordPress is magic!
👍
You don't use a nonce? Why not?
Yes, I do! You can use wp_create_nonce() as a hidden field when using AJAX with WordPress. I think it may be a little out of scope for this tutorial, but definitely a great way to add security and check if the ajax request is coming from your website or not. I added a nonce version to the tutorial for more advance users.
well sorry, I can't understand the positive comments here^^ in my opinion the explanation in this video is very superficial - for example, you don't explain why you need the "action" property (i don't know it why?), you don't explain why you write "wp_ajax_example_ajax_request", and you don't explain how it works^^
Kindly speak English in neutral accent so as to understand easily.
I have a California accent, as that's where I was born and raised. It's as neutral as I can get. :)