It’s always advised to use $wpdb->prepare
when you are taking input from user. This will help in protecting queries against SQL Injection. For more details, check the Codex
When you use $wpdb->prepare
, you must pass the variables to the query. In your case, you can skip using $wpdb->prepare
as you are using a hard coded value. But if you have the same value in terms of a variable, you need to modify it as below
$post_type="attorneys";
$wpdb->query(
$wpdb->prepare(
"DELETE a,b,c FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID=b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID=c.post_id)
WHERE a.post_type=%s",
$post_type
)
);
Related Posts:
- Why is variable not working on custom sql query using wpdb?
- Get stock by custom meta field on all Woocommerce variable products
- Any possible way to make $wpdb->get_results() return anything else than array?
- Echo a hierarchical list of post data from custom fields
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Can’t update multiple rows with $wpdb query
- PHP -> SQL Query with Summing
- Why my query does not run with prepare
- Undefined variable: row?
- Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
- Help with a $wpdb MySQL Query
- WordPress SQL injection
- Which is the correct way to conditionally enqueue a CSS file?
- Fatal error: Call to a member function query() on a non-object
- Odd / Even posts add class minus first post
- unable to use ‘new WP_Query’ in AJAX call
- Custom array from a query only write the last row of the query
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- Error using WordPress $wpdb object to get result from custom table
- How to retrieve the data from the sever and displaying it in a page?
- How to list commenters and days since last commented
- Querying Database with wpdb
- How to add div blocks after certain set of post
- $wpdb returns duplicate posts
- How to overwrite orderby with add_query_var
- Mixing variables into an array when inserting values
- working with term_relationships table
- Wpdb->insert() doesn’t insert new row after the last one
- how to get serialized post meta
- WordPress query undefined offset in loop
- Can I make get_users() query global?
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- Issue with custom loop in Archive page
- How to display SQL query that ran in WC_Order_Query?
- How to get specific attribute from DB
- Basic wpdb update question
- Custom Post type slider with thumbnail navigation
- I can’t update my data through $wpdb
- Parse error: syntax error, unexpected ‘}’ [closed]
- wpdb Cannot Update column in Database
- Output: “Array”
- Shortcode to pull posts
- How to use mysql LIKE with wpdb?
- How to hide posts of a specific custom category in WordPress?
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Delete database record using plugin from admin panel
- Cannot access $wpdb, comes back NULL
- Wpdb get->results to out the the month from the db
- How do I prepare strings for insertions as values into a MySQL table?
- How to use AJAX in WordPress in MYSQL query?
- WordPress PHP syntax doesn’t seem to be working correctly
- Change MySQL PDO connection to a WPDB connection
- Querying for specific tags
- WPDB – Read and write value from / to database
- How to get thumbnail with pure PHP in a WordPress database?
- Limit tags shown in post
- $wpdb->get_results breaking page?
- form $_post action value gets truncated after it passes through two forms
- How to Generate a list of Most Commented post?
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- wpdb getting avatars and author url
- mySQL queries are executed twice on wordpress website
- List of Events with Multiple Dates: Only NEXT Date
- Echo array value
- Add row to custom database Table and delete all rows older than 1 day
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- select a single val though a table in wordpress
- WordPress SQL JOIN query
- populate select options from extra mysql table data
- Query the links Database
- Fetching review value using wpdb class
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Display latest post from WordPress Featured Category that is also in X,Y,or Z categories
- Query pulling a single post per month
- WordPress Custom Query: Combining Two Functions
- SQL error with custom query
- WordPress is removing query variables like page, p from the URL of a custom static page
- WordPress Conditional / Multiple Taxonomy Query
- How can I modify this code to make the search box include tags and meta
- MySQL Query Returns Array () In Shortcode
- WordPress get last inserted user id
- Add posts to custom table in database instead of wp_posts
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Reject all malicious URL requests functions.php
- Advanced Query posts
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Database SQL query error
- How can I check that the acf field value is not a duplicate when adding a post?
- WordPress SQL Prepare
- Build A Custom SQL Query for WordPress Search
- My Custom Post Type AJAX Query is Returning no posts – why?
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Display articles with a different template in the home page | Solved |
- array wordpress when get is null
- Reading URL Parameters
- Creating multiple tables with Plugin