How to Post Data Using Ajax in WordPress

| Last Updated: | In: WordPress, WordPress Beginners


Hi friends, hope you are doing good. In today tutorial, I will explain how to post data using ajax in WordPress without using any plugin and also without creating a new plugin.

In this tutorial, I will show you how to get data from database by using the ajax in WordPress with the help of functions.php without using any plugin, so keep your close attention in this post. Please make sure you have already included the latest version jQuery. You can download the latest version of jQuery from here: http://code.jquery.com/jquery-latest.js

How to Post Data Using Ajax in WordPress

Open your functions.php file from your current activated WordPress theme folder and add the below code at the end the file and save. This function will include the autocomplete JS and autocomplete CSS in your site.

Now create a jquery.custom.js file in your JS folder and add below code snippet. The below code will post the user input data from search textbox to fwm_autocomplete function which is written in functions.php file.

Now again go to the functions.php file and copy paste below code at the end of the file and save. Below code will fetch the data from the database table based on the user_input data and return in JSON format. You can use that data where you want.

Over to You

Hope this tutorial help you more, do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:


, , , , , , , , ,