What you’re doing is safe.
However, some notes:
- See the
WP_User_Query
class in the Codex. This is the, “official,” way to do something like this, although you’ll get an integer-indexed array ofWP_User
objects. Instead of theARRAY_A
that you’ve specified. - You probably don’t want
_my_table
, unless your table is called something likewp__my_table
(note the double underscore afterwp
). The prefix returned from$wpdb->prefix
includes the underscore that many installations use after the prefix. - The
trim()
call aftersanitize_user()
is superfluous. It doesn’t hurt anything but it’s also a waste of compute cycles. - You may be able to write this in one line:
$results = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}my_table where name = %s", sanitize_user($_POST['name'])), ARRAY_A);
This may be better or worse for you.
Related Posts:
- correct sql query
- SQL query, error
- problem with sql query
- Show a different number of posts per page depending on context (e.g., homepage, search, archive)
- What are the common security flaws I need to look for? [closed]
- Making my plugin multi-site compatible
- Creating 20,000 Posts or Pages using a .csv file?
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- What’s the easiest way to duplicate an entire navigation menu?
- Using nextGen Gallery.. how can I call a list of all Gallery Names?
- Search and replace text across all posts
- Updating WooCommerce variable product stock issue
- bulk post_content update
- How can I get a list of plugins and which blogs are using them?
- What is the easiest way to implement cascading database upgrade for my plugin?
- [Plugin: Posts 2 Posts] How does it work?
- Post query – show posts from specified day and month and whole years
- Plugin Development sqlite or WordPress’ database
- Retrieving a Value from a wp-database
- Plugin echos text from shortcode function in gutenberg page editor
- Problem with creating tables for Plugin
- Prevent duplicate records in plugin table
- WordPress WPforms customization
- How do I run SQL queries on a WordPress web page? [closed]
- Migrating to WordPress Recipe Plugin and Some SQL Issues
- WP Query. Is there a maximum size?
- WordPress and a secondary database?
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- WooCommerce search products between price range using WP_Query
- How to create multiple database tables on plugin activation?
- Does deleting a Plugin via the WordPress admin ‘completely’ remove the code?
- Speeding SQL queries for a large database?
- $wpdb update query in plugin only updating one column
- Create a post builder skin in a plugin
- Taxonomy Drill-Down / Plugin Help – hierarchical queries within plugin?
- How to customize a title by passing query string?
- What is the best way to cache pages on WordPress
- Always get creating a new table with foreign key
- Woocommerce Backend Search by Title and SKU
- add_query_arg not work in admin
- Deactivation Hook does not remove database
- How to return the values from a row where a value occurs for the first time among the rows available?
- How to use apply_filters?
- Using AJAX to run SQL statement and populate dropdown
- Adding CASE in WP_Query
- JOIN and SUM different statement results (Mailster Database)
- How to search post titles with whole words only, but not the exact word only?
- How to get specific column data conditionally in database in WordPress?
- Change language on website and change currency with url query
- Memcaching recurring SQL Queries
- add products to WordPress site automatically
- How to get database connection details without longing to cpanel in WordPress?
- Performing CRUD operations on front end in wordpress
- Displaying different content depending on variable
- How to create algorithm for ordering posts in WordPress?
- Display a number value from mysql query in WP
- Looping the data from WordPress database using foreach
- How To Toggle User_Meta in frontend in a form using PHP
- Get and Update Most Meta Value as an array in HTML form
- WordPress filter from custom table is not working properly
- errno: 150 “Foreign key constraint is incorrectly formed” [closed]
- Multiple Meta key in search
- Having trouble going from Jfiddle to implementing in WordPress :(
- Create Array from data in the OPTIONS table
- Proper way to trigger a MySQL query via link in a plugin
- get_var result empty for query of custom table in plugin admin
- WP-Snap too slow (caused by WP_Query?)
- why the current date do not update
- Custom Table doesn’t create on plugin activation
- Using wp config to connect to a DB from a plugin
- correct validate inputs
- Get all the related data from WordPress DB
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor
- How to change and edit users according to the extension in the URL
- Is there any record of installed plugins in the database?
- Custom headers for the WordPress plugin directory
- Is it possible to run plugin code when a multisite blog is deleted?
- AJAX Call Via Vanilla JavaScript In WordPress Plugin Development
- What Triggers a Plugin Update Alert
- WooCommerce Dynamic Cart Pricing
- How to make first_name and last_name required fields in user profile?
- Can we use a webservice with WordPress?
- How I can get custom field’s current value?
- Checking instances of scripts in wp_head
- (FES EDD) New vendor submission page is blank
- After plugin activation all users marked as Spam
- Replacing global wp_query
- how to make wordpress plugin from PersianWebToolkit? [closed]
- Custom search search does not work?
- Add custom PHP and HTML to the_content()
- $wpdb not working wordpress plugin ajax call
- Woocommerce – Change variations output
- Adding featured image to post display widget
- How to create a WordPress sandbox on a live server for website development?
- Deleted plugins displays error message
- __FILE__ in WordPress plugins
- cmb2 select option output [closed]
- Jquery post responses 500 error after some time and lastly an 503 error
- Private plugin updating – GitHub zip file changes the plugin directory (with release or branch name)
- WordPress custom block: Link saved in database not retrieved when editing post