You can execute arbitrary SQL statements with wpdb::query(), including Data Definition Statements, e.g.
function
create_index ()
{
global $wpdb ;
$sql = "CREATE INDEX my_index ON {$wpdb->prefix}my_table (my_column)" ;
$wpdb->query ($sql) ;
return ;
}
Note: Because $wpdb->query()
can execute arbitrary SQL, if the statement you pass to it contains ANY user input, then you should use wpdb::prepare() to protect against SQL Injection attacks.
But this raises the question: how did you create your plugin-specific tables? “Manually” or programmatically? If programmatically, did you not use $wpdb->query()
? If you did it “manually”, then you really should create the tables (and their indexes) upon plugin activation.
See the excellent answer to this other WPSE question for how to hook into plugin activation (and/or deactivation and uninstall) to do things like create private tables.
Related Posts:
- 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
- How to create custom tables in WordPress using my own plugin?
- 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
- can not serialize and insert data from custom form
- Unable to override pluggable function wp_mail
- Avoid class name collision when using third party libraries in plugins?
- Access WordPress database outside of WordPress
- New User Form – Custom Menu Page
- Own plugin corrups plugin-activation
- wordpress plugin is not activating from widget
- All Users > User List > Update User Meta Field Inline
- Checking instances of scripts in wp_head
- How to access data in wordpress database externally using php
- How to save post change url youtube link?
- Best approach to fetch data from wp options to js file or php file
- Correct way to perform non-cacheable DB query
- Allow users of my plugin to define their own shortcode rather than use mine?
- uninstall.php file in Plugin to clean DB
- Archive – same title for the first two posts
- Creating a plugin to sanitize comment and the url field before display only
- Edit Yoast SEO breadcrumbs output [closed]
- Creating plugin using simple_html_dom parser?
- Object Oriented Plugin not working
- WordPress Settings Lost After Site Migration
- Does WP identify plugin by plugin name or plugin_basename?
- switched from query_posts to WP_query, not working now?
- Making a plugin only available on the front-end for the logged in super admin
- Create entire wordpress as a github repositery?
- When to load auto-login code?
- AJAX search posts and pages
- How to find the origin of a file upload from within wp_handle_upload?
- How would I go about creating a user ranked post popularity page?
- CSV file generation failing
- Updating the Drag-To-Share eXtended share URLs?
- finding whether request is for post, and post id
- Building plugin with changeable custom post type values…advice needed
- How to get all of the activate_plugin action parameters?
- __callStatic method handler passed to add_action causes bug in PHP
- Enqueue WordPress plugin scripts below all other JS
- Display update notification messages like ‘What’s New’
- How to add Internationalization in WordPress using Javascript/React?
- custom user tables supported in SharDB plugin?
- CRUD and Frontend show from a custom table without shortcode
- How to get specific setting by settings_fields()?
- Save / Show multi line text in metabox
- Creating mySQL procedure with $wpdb
- how to disable blockrenderAppender inside all Innerblocks?
- why doesn’t this update part of this plugin work? it take me to nothing here page
- Redirection of users away from wp-admin (but not administrators)
- WordPress Gutenberg react make import of __experimentalUseInnerBlocksProps which is no more experimetal
- Using a custom plugin to capture input data via Ajax and PHP
- Python with wordpress plugin
- Display post lists in 2nd paragraph
- Map Custom Registration Fields to WordPress User Roles
- Not able to add option in Sub-Menu under page
- How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
- Using a post-signup hook to get user details
- DROP TABLE with uninstall hook not working
- How to check if tables in WordPress still exists after activations
- How to apply a patch via plugin?
- Fixing WordPress’s Bug (failed to send buffer of zlib output compression) results in “White Screen of Death”