Check if current site ID and value exist in WPDB

Note that you should be able to map domains without 3rd party plugins. Here’s an untested suggestion for your callback in your current situation: global $wpdb; // Nothing to do if not multisite if( ! is_multisite() ) return; // Define the custom table $wpdb->dmtable = $wpdb->base_prefix . ‘domain_mapping’; // Check if the custom table exists … Read more

WPDB Join with custom table

I think you need to distinguish which table your ID and post_id come from. Take a look below and notice how the tables get a variable assigned. You could also just use the table name, but this reads easier. SELECT P.post_id FROM [prefix]_calp_events as EV JOIN [prefix]_posts as P ON EV.ID = P.post_id You stated … Read more

How do I prepare strings for insertions as values into a MySQL table?

dbDelta is really meant for creating databases or tables, not inserting records. I’d suggest using $wpdb->insert(), which will escape the values for you: $wpdb->insert( $wpdb->prefix . ‘w2bw2c_venue’, array( ‘market_id’ => 7, ‘venue_name’ => get_the_title( $id ), ), array( ‘%d’, ‘%s’, ) ); I’ve just used the name field you were having trouble with in my … Read more

$wpdb query outputs php code instead of executing it

It’s very clear that your file is not executing PHP functions, and the problem probably is because you are saving this file as something.html, storing it inside your theme or WordPress installation directory. What you can do, is to wrap this as a function or shortcode, and then create a page and use that shortcode … Read more

$wpdb->insert() doesnt work anymore

examine below example and figure out what is wrong with your code. global $wpdb; if(isset($_POST[‘submit’])) { $table_name = $wpdb->prefix.’employee’; $wpdb->insert( $table_name, array( ‘first_name’=>$fname, ‘last_name’=>$lname), array( ‘%s’,’%s’ ) ); use global $wpdb; global $wpdb; $table_name = $wpdb->prefix.’rdp_banners’; $wpdb->insert( $table_name, array( ‘banner_id’ => $banner_id, ‘rdp_banner’ => $rdp_banner, ‘banner_type’ => $banner_type, ‘customer_id’ => $customer_id, ‘status’ => $status, ‘company_name’ … Read more

Select two value from meta key and post meta

You just need to join postmeta twice: global $wpdb, $bp; $user_id = get_current_user_id(); $query = $wpdb->prepare( “SELECT rel.post_id as id, rel2.meta_value as val FROM {$wpdb->posts} AS posts LEFT JOIN {$wpdb->postmeta} AS rel ON posts.ID = rel.post_id LEFT JOIN {$wpdb->postmeta} AS rel2 ON posts.ID = rel2.post_id WHERE posts.post_type=”books” AND posts.post_title LIKE ‘%%fire’ AND posts.post_status=”publish” AND rel.meta_key … Read more

How to delete a particular row in a database table

Yes, you can use wpdb to delete the record in the custom table. Something like this in the wordpress function. require_once (‘../../../../wp-load.php’); if (!empty($_POST[‘id’])) { global $wpdb; $table=”table_name”; $id = $_POST[‘id’]; $wpdb->delete( $table, array( ‘id’ => $id ) ); }

Custom tables and using wpdb to insert into DB from a html form

You’re using a placeholder (“%s”) in your SQL for prepare, but you don’t pass it a value to put in place of that placeholder, hence the complaint. use $wpdb->prepare(“SELECT … %s”, $myvalue) And I’m pretty sure your other error stems from you passing in a DateTime object. $wpdb will not convert that automatically, it expects … Read more

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