Muhammad Adnan

Hi! I am Adnan, a Full time freelance developer who gets his hands dirty with php,xhtml/css,PSD Slicing and Conversions to Xhtml/CSS, jquery,wordpress,oscommerce and facebook programming. I am presently attending the great Virtual University of Pakistan to earn my MS in Computer Science by the end of 2010. Find out more about me at my blog and tweets

29 responses to “How to Implement Ajax in WordPress Themes”

  1. jinesh

    hi,

    I am a new for wordpress, and i want to know that where to make this implement_ajax.php file in theme folder?

    Please help me….

    Thanks in advance

  2. John J. Camilleri

    One thing I noticed is that you cannot write an AJAX handler ONLY for the frontend;
    In other words:
    `add_action(‘wp_ajax_nopriv_my_special_ajax_call’, ‘implement_ajax’);`
    will not work without the
    `add_action(‘wp_ajax_my_special_ajax_call’, ‘implement_ajax’);`

    Or rather everything will seem to be fine, but you will always get a response of 0.

  3. gunter

    Hi,
    I keep getting -1 as the returned value. The id of the selected category is passed on to the javascript but the return from the function is -1. Any help would be appreciated.
    Cheers

    1. Darren

      I’m actually getting the same problem with the “-1″ showing up.

      At first I thought it was Wordpress saying there was no data to return or a similar error. It turns out I was returning the data in the PHP function when what I needed to do was echo it. As such, the data returns and displays fine.

      It seems the “-1″ is related to whether or not the user is logged in. When I logged in, it changed to “0″. Still searching for a solution.

    2. Darren

      Ah, I figured out why it was showing the “-1″ and “0″. I had neglected to put in the “die();” at the end of the PHP function.

      If your data is not showing up, it is likely due to mis-named functions or a typo in your code, probably not related to the “-1″/”0″ issue you’re seeing.

  4. miniMAC

    Thanks for this article!

  5. Sovit Tamrakar

    Thanks, this helped me a lot. :)

  6. Abhinav

    Hi

    I followed the tutorial. It was really helpful. I am not sure what am i doing wrong because my ajax call made successfully but it always return back “0″. Can you please suggest me how to debug it?

    Thanks

  7. 45+ Fresh Wordpress Tutorials « MoeMir

    [...] How to implement Ajax in WordPress Themes [...]

  8. Tim

    Nice. Am going to try this out. Isn’t adding code to functions.php a bad practise? Isn’t there an alternative for that?

    1. zm

      that’s actually best practice. adding content to functions.php in your themes folder.

  9. 45+ Fresh Wordpress Tutorials, Techniques and Hacks | WebDesign Collection

    [...] How to implement Ajax in WordPress Themes [...]

  10. 45+ Fresh Wordpress Tutorials, Techniques and Hacks - Speckyboy Design Magazine

    [...] How to implement Ajax in WordPress Themes [...]

  11. Beppe

    Hello, very great tutorial. I would ask if is possible have four dropdown menus…? Many Thanks!

  12. Top 10 WordPress Tutorials And Articles From March

    [...] How to Implement Ajax in WordPress Themes [...]

  13. 75 Absolutely Stunning pieces of Eye Candy Photos And Works | All Mint No Hole

    [...] How to Implement Ajax in WordPress Themes [...]

  14. links for 2010-03-30 | AndySowards.com :: Daily Professional Web Design, Development, Programming Freelancer, Hacks, Downloads, Math and being a Web 2.0 Hipster?

    [...] How to implement Ajax in WordPress Themes | Graphic and Web Design Blog Really good tutorial on Ajax in WP (tags: wordpress ajax tutorial howto webdesign template wp) [...]

  15. Squiders

    great tips, has got me thinking of plans!

  16. Chris

    Great tut my friend, You can also checkout the article from Chris Coyier from CSS-tricks from last month: “AJAXing a WordPress Theme” http://bit.ly/aQjo9G

  17. Jake Goldman

    To prevent conflicts with other jQuery enabled scripts, you should really use wp_enqueue_script above the header to load jQuery.
    .-= Jake Goldman´s last blog ..Will HTML 5 replace Flash in the next 5 years? =-.

  18. Dragon Blogger

    Really nice tutorial, does adding ajax add overhead to blog load times? If you have particularly large amounts of categories? I also need to read more about creating wordpress templates.
    .-= Dragon Blogger´s last blog ..What Are the Easiest Ways To Monetize Blog Traffic? =-.

  19. the.dentist

    Nice, but it would have been much more useful if it dealt with something more practical.

    1. Muhammad Adnan

      This is really a simple example. You can use it anyway you want !

  20. Rilwis

    Nice tutorial. I like this type: step-by-step, code and screenshots included.

    But in this post, is it a mistake when you name the action “wp_ajax_nopriv_my_special_ajax_call” while in the code above you make a request with data: “data:’action=my_special_action&main_catid=’ + $mainCat”? I think it should be “wp_ajax_nopriv_my_special_action”.
    .-= Rilwis´s last blog ..JS Slideshow, CSS Reference, Mã hóa dữ liệu, WordPress Custom Functions =-.

    1. Muhammad Adnan

      Yes, it is a typo mistake :)
      very happy you pointed out it.
      .-= Muhammad Adnan´s last blog ..FREE PSD to XHTML Conversion ($123 value) =-.

  21. ebsoft

    Nice tutorial
    I hope can implement ajax in my blog
    Thank you
    .-= ebsoft´s last blog ..Simpan dan baca Google Map/Earth secara offline dengan GMapCatcher =-.

  22. emano

    very useful guide! great! :)

  23. WPLINX.COM » Hello world!

    [...] How to implement Ajax in WordPress Themes | Graphic and Web Design … [...]

  24. Lena Tailor

    Appreciate Efforts.

    Great post, I am planing on implementing it on my personal Blog.. Tx

Leave a Reply