I am not understandinhg $wpdb->prepare correctly

Ok, so there is one major problem with your code and it has nothing to do with escaping LIKE statements in SQL. But let me start from that… There is nothing wrong with your escaping. You should do it exactly like that: global $wpdb; // Create a SQL statement with placeholders for the string input. … Read more

How to add/change a value of $wpdb property/var?

Yep, just declare global $wpdb early enough and modify its fields. Codex docs for add_metadata() say exactly that: Note that you will also have to register the table with the $wpdb object in order for it to work. Simply add the following to WordPress’ init hook (or at least before you attempt to use any … Read more

Query WP data with the WPDB API from outside WordPress

Forgot to mention something: file1.php (with all the SQL functions) does include wp-config.php to get the DB info, which could be related to this issue, right? Dollars to doughnuts, this is your problem. You should never, ever, ever need to load wp-config.php directly. Are you trying to access WordPress functions from outside WordPress? Edit To … Read more

Get multiple custom field values in a $wpdb query [duplicate]

You are going to have to JOIN twice on the postmeta table. Something like: SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name, wpcflat.meta_value AS latitude, wpcflong.meta_value AS longitude FROM $wpdb->posts /* First Join */ LEFT JOIN $wpdb->postmeta as wpcflong ON $wpdb->posts.ID = wpcflong.post_id /* Second Join */ LEFT JOIN $wpdb->postmeta as wpcflat ON $wpdb->posts.ID = wpcflat.post_id LEFT JOIN $wpdb->term_relationships … Read more

How to check for empty and not a failure

You test for a fail by explicitly testing for false: if (null === $mypostids) { /* it failed */ } NB: three equals signs! you want to check for identical, not just equivalent edit: originally said false, changed to null after looking at get_result() function in source.

$wpdb insert array

What is your table structure. Please be aware that a $wpdb->insert call translate the array to an sql statement of the form INSERT INTO table_name VALUES (value1, value2, value3,…) Since there is no such thing as an array type for colums in sql, you will need to either serialize any subarray or make a seperate … Read more

Using $wpdb Class to Pull Recent Comments Across a Network

Why not use get_comments(), instead of trying to roll your own with $wpdb? function display_sitewide_comments() { $sites = wp_get_sites(); $network_comments = array(); $max = 20; foreach( $sites as $site ) { switch_to_blog( $site->blog_id ); $args = array( ‘number’ => $max, ‘status’ => ‘approved’, ); $network_comments[$site->blog_id] = get_comments( $args ); restore_current_blog(); } // inspect the comments … Read more

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