Tuesday, 12 March 2013

Inserting Data to Custom Table in WordPress | PHP Tutorials for Beginners


In this tutorial of php code for beginners we will show you how to insert data to custom table in WordPress

We are using different table of WordPress to fetch or store data. But some time during customization we need to create our own table in our WordPress database and store or fetch data from it.
For WordPress expert it very simple thing but for beginners it took time to R&d on this. So I thought make it simple and show you the simple step to add your data in your custom table of WordPress.
<?php
global $wpdb;
$wpdb->my_custom_table = 'my_custom_table';
$query = $wpdb->prepare("
INSERT INTO $wpdb->my_custom_table
(id, name, date)
VALUES ('','Neel','$date')
");
$results = $wpdb->query($query);
?>
Hope this php tutorial is useful for you. Keep following PHP Tutorials for Beginners for more help.

2 comments:

  1. Hello where file insert this requete ?

    ReplyDelete
    Replies
    1. $wpdb->my_custom_table = 'my_custom_table';
      'my_custom_table' is the name of your table in which data is inserted.

      Delete