If you look a bit into the source, you’ll see that $wpdb->insert()
will use ->query()
under the hood. So should be the same, right?
Not that simple. It doesn’t just use ->query()
but also ->prepare()
, which is considered best practice. Meanwhile with your code example you’ve probably just opened yourself to SQL injections.
The takeaway here: If it is a simple operation and the ->insert()
etc. method work – use them. They’re tested and contain little risk. Writing your own queries always carries the risk of opening yourself up to troubles such as SQL injections.
Related Posts:
- Connecting to a 2nd DB gives me no results when querying
- wp_usermeta – Read from database, but save function broken
- SQL error with custom query
- Writing a function for WP Cron to run a SQL command daily
- Delete oldest wordpress post (SQL query)
- Function returning queried meta value based on current post ID
- Order posts (across the whole site) by metadata date
- Sort posts by Date (DESC) and by Title (ASC)
- Filter the query ONLY for the search results page
- mysql custom wp query
- Delete post revisions on post publish
- How to sort results from a custom database table
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- How to update BuddyPress xprofile fields programmatically? [closed]
- Change all http to https in mysql databse?
- WooCommerce – Query for ordered products
- How to find if a post with custom_field == X exists?
- WP database error for comments_popup_link()
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Query WordPress database by registered date and role
- How to get last updated row or ID in wordpress
- Removing the first image in content
- How Do I Merge Categories With phpMyAdmin
- Best Practice for Syncing Local Development With Staging Development [closed]
- greatest() function returns undefined property
- Check if row exists before inserting
- Select Multiple meta_value from WP DB; Single Query
- Remove the deleted users avatar from list
- exclude a category from a search on a specific page
- example of build_query function?
- when I fetch data from remote mysql database in wordpress built in wordpress function is not working?
- CRUD operations using WordPress database API
- WordPress shortcode attributes for database SELECT?
- Shortcode pagination not advancing
- Create WP_Query to search for posts by their categories or their parent/child categories
- Advanced SELECT query with condtional statements
- Dynamic dropdown from database table
- Updating Media Published Date When Parent Post Is Modified in WordPress
- Create a new query in function.php to filter blog posts
- Slow queries constantly getting stuck on WordPress database of ~100,000 posts
- Get User Login Data (date, time… )
- Multisite 404 on pages – rewrite error breaks database
- Accessing two databases wordpress
- Query multiple tables at once?
- Is There Any Built In WP Functionality For Combining Form Fields To Return Specific Data
- How to ignore posts in pre_get_posts?
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Custom WordPress Table wpdb
- Best practice to limit results in get_row()?
- Always get creating a new table with foreign key
- Check if a value exists in database table
- SQL query to set posts in bulk based on the post content
- Query Column of Specific ID from Database Table
- get_terms (or tax_query) for term of current post?
- shorthand syntax for custom fields
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- How to avoid saving empty data to sql while using add_meta_box
- Using One Function To Create Two Different Shortcodes
- How to loop while adding data to database?
- How can I connect to a second database and still be able to use wp functions like get_post_types()?
- Update wp_postmeta table based on 2 keys
- Selecting specific query for offset
- Why isn’t comment validation working?
- WordPress Database Query works in phpMyAdmin but not in the code
- Button click counter for login user
- Function stops working
- Shortcode with pagination advancing multiple queries
- Populate custom post type/custom fields from an external database
- How can I display a query in a page?
- Get multisite count without php?
- WP_Query always returning the last custom post
- Database SQL Error, Should Work
- Database Query not working
- Function to get the name in database table from the comma separated string
- Check if values exists DB
- Sorting date results from a query
- Functions file mods and CPU
- How to Delete Posts by title?
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Bulk set Post Title as Tag where Tag is Empty Function
- Enqueue script o style only if a template part is loaded
- Can I pass two roles to the function get_users?
- Database slowdown after update to 3.4.1
- How to insert data into MySQL database from the form created in WordPress site
- Dumping variable in custom pre_gets_post function in functions.php, returns NULL
- ACF not showing
- Cannot modify header information – headers already sent (wp_redirect in functions.php)
- How to remove comment count column in Posts inside the admin dashboard?
- Function not working inside of a function in functions.php
- How to Use Global Variables Inside Header and Footer
- Redirect website domain (including all pages) to external URL after Popup message (few seconds)
- Trouble running $wpdb->query() with last_insert_id
- External wpdb connections in different plugins on single page
- Integrating Custom Database with WordPress
- Check if almost 10 year old – working code is up to date
- Remove all video attachment, both files and post/postmeta from database?
- Dynamically generated Navigation Diagram using Custom Fields
- Full size image option removing problem
- Need to use an external variable inside a function
- Add functionality to block comment authors in the Comment edit pag