how to use $wpdb->prepare to update a custom table

When you look at the Codex article on $wpdb, then you will see that your current usage is correct. The last argument array( ‘%s’, ‘%d’, ‘%s’ ) already indicates that there is something like sprintf/printf going on in the background. The $wpdb->prepare() method isn’t needed for every other method. The ones that need it: $wpdb->query() … Read more

$wpdb->prepare with ON DUPLICATE KEY UPDATE

It’s my fault. Got the solution after @Otto’s comment: Do you actually have a duplicate key here? What is the structure of user_req and what are the keys and indexes? Here’s how my SQL query should be: INSERT INTO {$wpdb->prefix}user_req ( user_id, post_id ) VALUES ( %d, %d ) WHERE NOT EXISTS ( SELECT * … Read more

Better way to migrate to server?

I personally use BackupBuddy (a paid solution, from iThemes.com). For your scenario, you could install it on your local dev machine, and perform the following one-time actions: Add a one-time configuration for your server as a “Remote Destination” (including FTP/sFTP credentials and target directory). Copy an ‘importbuddy.php’ script to your remote server. Then, whenever you … Read more

How change user type from contributor to author

I recommend backing up the database before making any major/bulk changes to it. First you need to get all users with the role “contributors”, then update their roles to “author”. $contributors = get_users(array(‘role’=>’contributor’)); foreach($contributors as $contributor){ wp_update_user(array( ‘ID’ => $contributor->ID, ‘role’ => “author”) ); } echo “done updating contributors to authors”; You could have this … Read more

problem with sql query in wordpress plugin

I think the problem may be with your wildcards. Because you’re trying to use Wildcards in the prepare, which takes %s, the WPDP doesn’t know the difference between the wildcard % and the placeholder %. Using this answer as reference: How to use wildcards in $wpdb queries using $wpdb->get_results & $wpdb->prepare? You’ll have to double-escape … Read more

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