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...

Комментарии • 49

  • @roeeangel3964
    @roeeangel3964 3 года назад +11

    Your guide is AMAZING !!! Thank you so much, this is the only video that explain clearly how to do that.

    • @shawnhayes
      @shawnhayes  3 года назад

      No problem. Super happy that the tutorial helped you! Thank you for the comment!!

  • @danielkndn
    @danielkndn 6 месяцев назад

    You are going to heaven 🙏 Thank you very much!

    • @shawnhayes
      @shawnhayes  6 месяцев назад +1

      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.

  • @vividlearner7427
    @vividlearner7427 Год назад

    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

    • @shawnhayes
      @shawnhayes  Год назад

      You want the call back in your functions.php to send back your shortcode. Something like echo do_shortcode('[your_shortcode]');

  • @Olamilekanfinal
    @Olamilekanfinal Год назад

    please what is adding tei-ajax-post=1 to the end of my URL, i was able to discover it on google analytic

  • @tanxyrogue847
    @tanxyrogue847 2 года назад

    you helped me understand ajax after years of struggling

    • @shawnhayes
      @shawnhayes  2 года назад

      That's awesome! I am so happy this helped you. Thank you so much for the kind words. You made my day! :)

  • @sahiku5357
    @sahiku5357 Год назад

    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

  • @taqimushaidi1414
    @taqimushaidi1414 2 года назад

    very very very very helpful. keep going and uploading videos like these.

  • @gonzalog2
    @gonzalog2 2 года назад

    Like, commented and suscribed! Your work is awesome!

    • @shawnhayes
      @shawnhayes  2 года назад

      Thank you! You are awesomeness!

  • @thomasorta4297
    @thomasorta4297 3 года назад

    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

    • @shawnhayes
      @shawnhayes  2 года назад

      This sounds like you are asking about something outside of the this video tutorial. Is that correct?

  • @VADIMAKE
    @VADIMAKE 2 года назад

    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 ...

    • @shawnhayes
      @shawnhayes  2 года назад

      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!

  • @DSPplug
    @DSPplug 2 года назад

    subscribed, thankyou.

    • @shawnhayes
      @shawnhayes  2 года назад

      You are very welcome and thank you!!

  • @DopetheKid
    @DopetheKid 2 года назад

    where did you get the information in the functions.php before you pasted the code in it?

    • @shawnhayes
      @shawnhayes  2 года назад +1

      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.

    • @moviespremiumtv2844
      @moviespremiumtv2844 2 года назад

      @@shawnhayes yes I want the code

  • @acidfather
    @acidfather 3 года назад

    Can we use this for making the ajax call for ACF repeater fields?

    • @shawnhayes
      @shawnhayes  2 года назад

      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.

  • @vencesgrapikatv9919
    @vencesgrapikatv9919 3 года назад

    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 "

    • @shawnhayes
      @shawnhayes  2 года назад

      Are you asking a question about the tutorial or a problem you are having with your own web development project?

  • @tahirhaithem9841
    @tahirhaithem9841 3 года назад

    Thanks

    • @shawnhayes
      @shawnhayes  2 года назад

      You are very welcome! Thank you for the comment!!

  • @hammaskermani1477
    @hammaskermani1477 2 года назад

    you are amazing

    • @shawnhayes
      @shawnhayes  2 года назад

      Thank you! You are pretty amazing yourself my friend! :)

  • @TristanCodes
    @TristanCodes 2 года назад

    Download isn't working giving me a bad page 404

    • @shawnhayes
      @shawnhayes  6 месяцев назад

      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!

  • @yazou123
    @yazou123 3 года назад +2

    What about nonce ?

    • @shawnhayes
      @shawnhayes  3 года назад +2

      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.

  • @ifelsedev
    @ifelsedev 2 года назад

    Thank you so much.

  • @randomprog115
    @randomprog115 3 года назад

    Thanks for this sir.

    • @shawnhayes
      @shawnhayes  3 года назад

      You are very welcome!

    • @shawnhayes
      @shawnhayes  3 года назад

      You are very welcome! Thank you for the comment.

  • @lunamoonfang8169
    @lunamoonfang8169 3 года назад

    can you do ajax with rest api?

    • @shawnhayes
      @shawnhayes  3 года назад

      Yes, I believe so.

    • @shawnhayes
      @shawnhayes  3 года назад

      Yes, you can! WordPress is magic!

  • @PiotrSygutPL
    @PiotrSygutPL 2 года назад +1

    👍

  • @ShannonWhitty
    @ShannonWhitty Год назад

    You don't use a nonce? Why not?

    • @shawnhayes
      @shawnhayes  Год назад

      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.

  • @kevin_neugebauer
    @kevin_neugebauer Год назад

    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^^

  • @ifelsedev
    @ifelsedev 2 года назад

    Kindly speak English in neutral accent so as to understand easily.

    • @shawnhayes
      @shawnhayes  2 года назад

      I have a California accent, as that's where I was born and raised. It's as neutral as I can get. :)