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
- Custom pages with plugin
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Redirect to settings page after install
- What is the correct way for a theme to support plugin UIs?
- How does WordPress determine the primary plugin PHP file?
- translation does not work with text_domain
- How to update widget_text in the wp_options table
- flush_rewrite_rules() not working on plugin activation
- Determine plugin name from within plugin_action_links filter
- Plugin Functionality Only for Editor and Administrator
- Having separate plugins and themes folder for multi-site setup
- If I delete plugins via FTP are settings kept in DB?
- Many plugins making WordPress run slow by design?
- How do I turn a custom post type into a plugin?
- Add keywords meta to index.php page
- Does WP identify plugin by plugin name or plugin_basename?
- How to check if tables in WordPress still exists after activations
- Modifying Author Link to add Author Meta in URL
- Force file download on plugin activation
- How to create a custom post type that contains another custom post type?
- wp_editor content in plugin options page
- Count posts by type including drafts and pending posts
- Redirect to another page using contact form 7? [closed]
- WordPress Multisite: Programmatically Activate / Deactivate a Plugin of a Specific Blog
- remove all submenus from plugin
- composer not working on my plugin when i upload it to my website
- WordPress Fatal Errors [closed]
- How to rewrite URL and get the values?
- How to access the WordPress DB from a plugin file
- Disable plugin visibility at the plugin directory
- How to deactivate my plugin upon deactivation of NextGen
- Widgets are not displaying in the admin panel
- How to overwrite the category template in a plugin
- Content-Security-Policy implementation with WordPress W3Total Cache plugin installed
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- show wc_add notices on particular page in woo commerce custom plugin development
- How to write different events from different functions in my file to a log file in WordPress
- Create a form and have custom menu display based on user answers?
- How to make a plugin api route have permission?
- Why my multisite is this slow? (stats inside)
- Modify Plugin PHP Class in Child Theme – Correct Method
- Problem with conditional woocommerce custom checkout field
- trying to create simple plugin to filter categories from all authors
- Change wp_mail SMTP settings for each E-Mail
- RSS Feed has no Items (Possible Plugins Conflict)
- WordPress Thumbnail add action if no thumbnail
- How can I add the custom taxonomy categories to the posts and pages?
- Allow users to enter and edit data in one-to-many configuration
- Pass strings to plugin function [closed]
- How to create a page template using custom plugin
- WordPress 3,5 and Jquery version
- contact form 7 captcha support anyother captcha plugin? [closed]
- Function not being called on form submit, only blank admin-post.php page
- How to give specific class name to category in wordpress with code snippets
- WordPress.Security.NonceVerification.Recommended
- BBPress Customization with Custom Plugin
- How do I apply different block supports to different parts of my custom block?
- Custom Gutenberg blocks not showing in WP editor