Sometimes you need to make a custom table in the WordPress database table. It is not so very difficult to insert data in the WordPress database table. Just follow the following steps.
step 01: First make table in your WordPress database tables name ctables with your required fields.
step 02 : Next you need to make a shortcode with a form to take input from input fields. I have made a shortcode named ctable_shortcode.php
<?php function get_ctable_form($atts, $content = null) { $form = '<form action="#" method="post"> <label for="name">Name</label> <input type="text" name="name" id="name" /> <label for="category">Category</label> <input type="text" name="category" id="category" /> <label for="description">Description</label> <textarea name="description" id="description"></textarea> <input type="submit" name="ctable_insert" > </form>'; return $form; } add_shortcode( 'ctable-form', 'get_ctable_form' );
step 03 : Next you need to make a functions file to insert input data from input fields to database table. I have made a function file named ctable_function.php
<?php if(isset($_POST['ctable_insert'])){ global $wpdb; $table_name = 'uploaded_srts'; foreach ($subs as $key=>$subtitle) { $data_array = [ 'name'=> $_POST['name'], 'category'=> $_POST['category'], 'description'=> $_POST['description'], ]; $result = $wpdb->insert($table_name, $data_array, $format=null); } }
step 04 : Next you need to include the files in the wordpress functions.
require get_template_directory() . '/inc/ctable_shortcodes.php'; require get_template_directory() . '/inc/ctable_function.php';
ok all sets now add the shortcode in a page and insert data according to your choice. So insert data in wordpress database and enjoy!
How to parse srt file and insert it in wordpress database
Your WordPress database stores everything that you need for your website. There are a million reasons why you might want to add a new WordPress article manually using MySQL. I wanted to migrate custom-coded photo gallery content into the main WordPress installation so that things on the website would become more streamlined and update-able. Most articles on the net push the idea of using WordPress’s own functions to add or alter blog posts in PHP (and probably for a reason).