MySQL database migration to WordPress

From technical perspective wpdb->prepare() essentially trickles down to escaping variables with either (depending on configuration) mysql_real_escape_string() or addslashes(). It’s not inherently more or less secure than any other properly implemented escaping routine. It is closer to specifics of WP and configuration it is aware off.

wpdb get_var is not returning any result (verified mysql query returns only one value)

I guess meta_key is not a number, so you shouldn’t use %d in yous SQL query. $wpdb->prepare( “SELECT meta_value FROM %s WHERE user_id = %d AND meta_key = %s”,$userMeta,$user_id,$practiceKey ); // meta_key = %s not %d PS. You don’t have to escape table name in this way. You can use $wpdb->prepare( “SELECT meta_value FROM {$wpdb->usermeta} … Read more

Update references to pictures on website after moving to new URL

Besides doing a custom query in your MYSQL database, I’ve found this little script to be helpful in my development process, and I’ve incorporated into my regular workflow to keep my local, development and production servers synchronized: https://github.com/interconnectit/Search-Replace-DB Just be sure to read the documentation, especially about overwriting GUID values and also make sure to … Read more

Inserting into data into external DB using WPDB

You are using $wpdb incorrectly Take a look at these lines: $row = $newdb->get_results(“SELECT * FROM chi_clients WHERE accountNum=’$acctNum'”,ARRAY_A); $name= $row[‘lastName’] . “, ” . $row[‘firstName’]; $wpdb->get_results is going to return an array of “rows”. It is going to multidimensional. You are treating it like it has returned a one-dimensional array. That is, this (completely … Read more

Using class id from array for query

Try this after your $wpdb query: // collect calendar id’s $ids = array(); foreach( $calendar_entries as $calendar_entries): array_push( $ids, $calendar_entries->id ); endforeach; // query the above calendar id’s $args = array( ‘post_type’ => ‘post’, ‘post__in’ => $ids, ‘orderby’ => ‘id’, ‘order’ => ‘DESC’ ); $query = new WP_Query( $args ); You can also modify the … Read more