This video tutorial walks you through the process of using ajax in the WordPress admin within your own plugins. The end result of this tutorial is not a complete plugin, but it does show the entire process, step by step, of how ajax is utilized in the WordPress dashboard.
Unlike most of my tutorials, I do not use any pre-existing plugin or code as reference during the video; it is all coded live during the video, so mistakes and small bugs are common, but they really help to illustrate issues that developers often encounter while working with ajax.
Thanks! Saved my life. Congrats.
Hey
This is looking really great, great video – I have however a problem, I am using it to import large xml feeds with products into wordpress.
in the aad_process_ajax php function I have added all my code that loads the xml file with simplexml_load_file and loops trough it in a foreach loop, where I define all the data needs to be insertet in the database, and it checks if the products exists, updates them with new prices if they do etc etc.
I can get it to run, but I think it crashes for some reasons, on small xml feeds with 100 products it runs them, but when I try with xml feeds with 14.000 products it stops inserting at some point, also on xml feeds with a 1000 products – but the loading gif just keeps running?
You have any idea, that could help me out?
Much appreciated:)
Are you attempting to process all of them at once or are you doing it in batches?
Hey Pippin,
Could you please give a brief tut on doing the same with WordPress plugins using WPMVC?
I hardly find any tip to succeed.. the WPMVC tutorial is of not much help..
Thanks..
Prabhu..
Great tutorial and very helpful for me. Thanks
What if I want to use a text field to search and retrieve a specific post by title and display it on the admin page?
You can definitely do that!
Is there a specific question about what needs to be changed to do that?
This is bloody amazing. Thanks a ton for taking your time to make this video. Truly amazing.
Also I have a question, I’m creating a plugin which is gonna show some stuffs in the dashboard widget using ajax, but not just once, its gonna keep updating the result after every 300ms.
Do, you think, its good to do that they way you showed above? I’m not gonna increase the server load for my plugin.
You may want to look into using the WP Heartbeat API: https://pippinsplugins.com/using-the-wordpress-heartbeat-api/
Thanks a lot for this tutorial. It helped me immensely with making an ajax call in the proper way on a certain post type edit screen in wp-admin.
Hi Pippin,
Your below article is great, well explained and a life saver for me in understanding the ajax implementation in WordPress.
https://pippinsplugins.com/using-ajax-your-plugin-wordpress-admin/
I had a question, as mentioned and explained by you that we need to add die() after the ajax response is printed in order to avoid printing 0. But I need to show data in 2 dashboard widgets. If I add die() then other widgets on dashboard would not show up else the 0 shows up.
Any ideas what can be workaround here?
Thank you in advance.
Sounds like your callback functions are being loaded globally instead of only during the ajax processing. You need to make sure to separate your global processing from the ajax processing in order to prevent what you just described.