Creating Tables with plugin This page shows how to work with tables in plugins. Example on that page includes table creation during installation of plugin. But it can be dynamically used also to create table. See below.
if(isset($_POST['create'])
{
$table_name=$_POST['table_name'];
Note : don’t use – in variable names.
global $wpdb;
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) DEFAULT '' NOT NULL,
UNIQUE KEY id (id)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
//create table query
header("location: add_table_attribute.php");
}
Related Posts:
- How to Add an Index to Plugin Database table
- Creating two database tables via plugin
- How does WordPress handle MySQL row lock errors?
- WordPress register_activation_hook table creation not working
- Default Plugin Settings Not Writing to Database
- Building an email signup form. Where should the information be saved in the DB?
- Plugin Options Not Saving to Database in WP 4.5
- Is it possible to create Custom Post plug-in?
- Help With MySQL to WPDB Query Conversion
- Prevent duplicate records in plugin table
- WordPress Backend HA (Automatic failover)
- How can I change the meta_key for a particular piece of information?
- Can I create a table on my DB without creating a plugin?
- WordPress : Explain Plugins & Theme string value in database
- Is it necessary to auto delete my WP plugin database tables when users deactivate/delete my plugin?
- How to insert and call new data in wordpress website database through a plugin
- WPDB: Update table
- Issue running db create table query from static method
- Separate database for a wordpress plugin
- Best/Correct way to add an option to a category
- What is the WordPress approach to custom data?
- How to create plugin/ page that reads from database
- DB Query not working in Plugin
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- WordPress plugin: efficient way to store large data
- Integrating Custom Database with WordPress
- How to display results from a data table with an encrypted user id?
- How to make a Product page without ordering and database
- I want to schedule email (date, time is in database->table) wp_schedule_event() not working
- How to securely controlling data without keeping it in postmeta?
- $wpdb->insert not working inside save_post tag
- Where do the section input fields values are stored in database
- My plugin can’t see my files
- how can i get records from wp_postmeta table using particular meta_key in database?
- Create New Admin Menu Section – Like how custom post type works, in a way
- Creating fields in the database
- How to submit the custom form data in database in WordPress without plugin?
- get_option returning a different value from what’s saved
- How can I delete the options from DB when the plugin is deleted?
- register_activation_hook not working
- On the same site, how do I send data from a plugin file to a theme file?
- plugin doesn’t retrieve data from database
- Namespaces in WordPress – How do I initiate the main class?
- Function to activate WordPress theme inside a plugin
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- Pass A Value From Outside To A Plugin Variable
- shortcode doesn’t work
- Built in admin ajax hooks?
- Could someone please help me to add category id with in this query so this will return posts from a certain category?
- How to handle autoloading with composer by keeping the WordPress naming conventions?
- What are the benefit in adding hook in the init() hook?
- building plugin and it is displaying above plugins page
- Where to hook my plugin’s action
- load_theme_textdomain path
- plugin development: problem with functions
- How to find the origin of a file upload from within wp_handle_upload?
- WP All Import – Execute Imports
- How to set taxonomy in custom plugin?
- Plugin development: Buggy plugin preview
- Unable to delete custom post types, confusion around capabilities
- How to create multiple database tables on plugin activation?
- where is the main file in this plugin?
- Insert Array in Plugin Database
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- plugin wraps the entire content
- Shortcode Attributes to Return different $_POST
- Plugin onclick button activate other plugin
- How programatically cause uploads folder to be created?
- Yoast SEO Plug In and my Theme duplicating code. Need some feedback on what to do? [closed]
- Using Class loader in WordPress boilerplate
- Allow a particular user to access a particular plugin?
- wordpress plugin add page when activate
- Add style to body based on url
- How to check for already existing plugin versions on activation? and prevent errors
- update_post_meta is not working for me when I use e.preventDefault for update button
- How to create a plugin with automatic update?
- Loading plugin script only on required page?
- Create survey that redirects to sidebar menu customized to answers
- Uploading images to custom table
- Changing author slug for a custom role without using plugin
- Plugin management with my custom plugin
- Plugin Version List not Shown
- How to pass value from WordPress to Javascript
- How do I create a state of “don’t assign anything to variable” if WP_Error throws an error?
- Plugin communication between sites that use it?
- Database error when user logs in
- How to change meta data(title, description) for current post?
- Provide http service by wordpress plugin
- create web service for android app using wordpress website
- WordPress custom posttype meta values doesnot save
- Why tinyMCE.editors doesnt work on tinyMCE
- Filter EVERY category link with my plugin
- get_option include in my adsense
- How can I make a website with dynamic features with wordpress?
- How to add custom html to the Media > Attachment Details modal?
- Displaying Category Feature image on loop
- How to check record is exist or not in WordPress CRUD Operation with $wpdb
- How to disable pagination in WordPress’ API results?
- How to change the version of block.js and plugin to the same of Package.json?
- Warning “Attempt to read property ‘feeds’ on null” using post update function