Word-press is CMS for websites but there are things when we need to use database or customize the pages as per requirements. Like if we want to use some database tables that are not related to WordPress but our customized tables then we use custom PHP in this regards

To use custom PHP to connect with Databases we use following WordPress plugin that allows us to write PHP code

Install and activate this plugin and then go to plugin/insert-php folder and create a php file when you can write connect php code for data base.

In above screenshot we have installed insert php plugin and then used the plugin folder and created download.php file , Inside this file we have written PHP code to connect data base and fetch results

Now question is how to use this PHP file with WordPress pages.

We have to use this file using AJAX call. Inside the WordPress page we have written ajax call through which WordPress page form parameters are sent to this php file and then forwarded to database.
On top of WordPress page write ajax script  in JavaScript tags.

   var name = $(‘#name’).val();

    url : ‘conceptover.com/wp-content/plugins/insert-php/download.php’,
    type : “POST”,
   dataType: ‘json’,
   data : {name:name},
    cache : true,
    success :function(resp)
         // This response have been taken from download.php file and this can be used on WordPress                 // page

Leave a Reply

Your email address will not be published. Required fields are marked *