First of all, you escape that query incorrectly… You should use esc_like
on the like part and prepare
should be used a little bit different:
$title1 = 'Gocomma 10W QI Wireless Fast Charger Car Mount Holder - 2pcs (it)';
$sql = $wpdb->prepare(
"SELECT * FROM {$wpdb->posts} WHERE post_title LIKE %s AND post_status="publish"",
'%' . $wpdb->esc_like($title1) . '%'
);
$post_if = $wpdb->get_results( $sql );
But there is one more problem with this approach. There is a chance that the -
character gets converted in some other character (like —
– dash) and so on.
Related Posts:
- How to use $wpdb to delete in a custom table
- get_results on large datasets
- Is there a (better) way to access $wpdb results?
- Using $wpdb generates DB error
- How do you use prepare when asking for a list of id’s
- how to execute different sql query in non-sanitized $wpdb->get_results function
- WPDB update row with != in where clause
- How to update records using $wpdb?
- Need help writing a $wpdb query
- show badge with count for pending items in custom post type
- WP Sql query multiple where clause
- WordPress SQL query – returning ‘true’ ‘false’ or ‘null’
- Modify the structure of data returned by $wpdb
- Syntax for $wpdb->prepare when searching in two columns
- Confused by $wpdb->prepare
- How to display user_nicename and usermeta values by custom query in WordPress?
- Optimizing WordPress Queries – Removing Group By ID
- How can I combine one field using wpdb and group by?
- $wpdb->prepare with ON DUPLICATE KEY UPDATE
- how to use $wpdb->prepare to update a custom table
- WPDB Placeholders and second argument for prepared statements
- Increment integer field in database when WHERE needs to be dynamic [closed]
- Custom SQL query ORDER BY term_order
- Custom $wpdb returns unexpected time based results
- How to left join meta in queries [closed]
- wpdb->get_row is selecting the variable as a column name
- CREATE TABLE with dbDelta does not create table
- $wpdb query outputs php code instead of executing it
- wpdb query not working
- WordPress wpdb->insert returns int(0) => doesn’t insert anything, no errors!
- WPDB SQL Ignore `post_status` Parameter
- how to list all post that are in the custom taxonomy using $wpdb
- WPDB SQL query SELECT from category
- How to use WHERE NOT EXISTS query to avoid duplicate entry using $wpdb to save in custom table?
- Creating an Angular factory from custom database table
- wpdb->update update the entire table instead of one row
- How do I update post based on meta_key in another table?
- How to set up prepared query using IN statement
- Custom database query to validate data
- Alter the main search query to search posts by coauthor user name
- Creates only one table and not the other
- Protect custom form from SQL injection
- looking for a way to allow users to backup the plugin db data(save as)
- SQL Query to select post title & post ID from a particular category
- Get comments after specific date
- Get count of rows based if column exists in two different tables
- query_vars doesn’t return query string (trying to get data from $wpdb)
- How do you properly prepare a %LIKE% SQL statement?
- How to parse row results from $wpdb -> get_results
- $wpdb->insert() and Values for Datetime Columns?
- Change post status based on meta value
- Speed optimization of $wpdb->get_results
- $wpdb is get_results escaped
- wpdb prepare: passing varible number of fields as second argument
- Wpdb query for comment meta for current post
- How to Modify this $wpdb query to accept an array of post statuses
- WPDB Update using Conditional Arrays
- How to correctly pass values to wpdb->prepare()?
- $wpdb->get_results returns empty but value exists
- Problem displaying inserted form
- Get published posts and pages?
- How to get a value-only flat array from $wpdb->get_results when selecting a single column, without foreach()?
- How to Instantiate wpdb Object in New File
- How do you build a wpdb query dynamically?
- Would this WPDB setup result in potential race conditions?
- How to update a row in a table in WordPress
- External DB Connection [closed]
- $wpdb->insert() does not Insert record in a table
- WordPress SQL Issue not returning correct reselts
- WordPress db prepare
- $wpdb->prepare with LIKE returning blank array instead of rows
- $wpdb update query in plugin only updating one column
- how to get db values without using an loop with wpdb->get_results()
- Trying to get variable from WP table and toggle its value
- Set MySQL variables in WPDB
- get_results query with accent
- Is querying wpdb directly and skipping actions provided by WP’s core “wp_update_post” a good idea?
- Using “->” in a page to exceute $wpdb query gives error
- Why my query does not run with prepare
- Exclude specific terms from all queries using posts_where or something similar
- wpdb getting avatars and author url
- query a newly created table using $wpdb
- Get all sticky posts from one user through user ID
- How do I query for posts by custom meta and those that have been stickied?
- WordPress SQL JOIN query
- Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX
- Any way to use FETCH_KEY_PAIR with $wpdb?
- Delete oldest wordpress post (SQL query)
- Prepare WPDB with meta key and meta value
- How to get row value from wpdb
- I am using wpdb but it not working perfectly.but if I dont use form data its work
- wont add form details to database or send me mail
- WPDP related functions look to work but they don’t
- why nl2br() is adding an extra ?
- How to add more custom fields in user meta table simultaneously
- get unserialized array without using get_option()
- Create Table Failed Column Date DateType
- How do I change the datetime format from ( ‘y-m-d’ ) to ( ‘d m y’ ) [closed]
- Table wont load into WPDB
- WPDB prepare – like % – placeholders?