Backticks (`) Instead of Single Quotes (‘) in an SQL Statement?

Backticks and regular quotes (both single and double) have distinct meanings in SQL. Quotes indicate a literal string, whereas backticks are quoted identifiers. This isn’t specific to WordPress, but rather a general way in SQL of quoting columns or tables. For example, imagine you’re running a query comparing two columns: SELECT * FROM wp_posts WHERE … Read more

WordPress SQL LIKE request doesn’t work for fields with special symbols

What I miss here? How to search through any elements in this field? Your SQL statements, or the LIKE ‘%a%’ and LIKE ‘%full%’, are good. But the wpdb::prepare()‘s documentation says, “Literal percentage signs (%) in the query string must be written as %%“, hence you should actually use LIKE ‘%%a%%’ and LIKE ‘%%full%%’. But then … Read more

How To Write An Inner Join With WP Query

Ok so the way I was able to just show English properties on the user admin page was with this posts_request hook: add_filter(‘posts_request’, function($sql, $query) { $is_user_edit_page = ( isset($_SERVER[‘HTTP_REFERER’]) && strpos($_SERVER[‘HTTP_REFERER’], ‘user-edit’) !== false ); $is_property_sql = (strpos($sql, ‘property’) !== false); if ($is_user_edit_page && $is_property_sql) { $sql = str_replace(“‘sp'”, “‘en'”, $sql); } return $sql; … Read more

Moving database with phpMyAdmin

I would do this so. But this is probably not the most efficient way accomplishing this task. There are several plugins out there, that may automate this. If anyone knows one, that is good, I would like to hear about it. Plugins that look promising: http://wordpress.org/extend/plugins/xcloner-backup-and-restore/ http://wordpress.org/extend/plugins/duplicator/ http://wordpress.org/extend/plugins/wp-migrate-db/ Find more at: http://wordpress.org/extend/plugins/tags/backup

How do I move a WordPress site to another server?

I do this all the time to move a site from our staging server to the live domain. I use PHPMyAdmin to export the database as an SQL file, then open it up in a text editor and do a global find and replace on the old url to change it to the new url. … Read more

How to properly sanitize strings without $wpdb->prepare?

I can’t use $wpdb->prepare, since I want to be able to add variables to my query string that look something like: $var = “AND pm.meta_value=”%$_POST[“val’]%'”; To get a literal % to pass through $wpdb->prepare just double it. You don’t need to be avoiding $wpdb->prepare. Proof of concept: var_dump($wpdb->prepare(‘SELECT * FROM {$wpdb->posts} WHERE post_title LIKE “%%%s%%”‘,’Hello’)); … Read more

prepare() not working

I agree with @bainternet. You don’t need $wpdb->prepare. There isn’t any user supplied content. The answer to the question is that to get a wildcard % to pass through prepare you need to double it in your code. LIKE ‘_transient_wb_tt_%%’ Try that or this if you want a good look at the generated query: var_dump($wpdb->prepare(” … Read more

SQL select of users by metadata

Double-check your SQL syntax. It sounds like you want to do a JOIN … But you’re not building the query correctly. It should be something more like: SELECT u.ID, u.user_login, u.user_nicename, u.user_email FROM $wpdb->users u INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID WHERE m.meta_key = ‘wp_capabilities’ AND m.meta_value LIKE ‘%supplier%’ ORDER BY u.user_registered You … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)