WordPress – wpdb query does not list same result as sql query
WordPress – wpdb query does not list same result as sql query
WordPress – wpdb query does not list same result as sql query
Update all fields of table with ON DUPLICATE KEY UPDATE command
dbdelta demands that: You must put each field on its own line in your SQL statement. You must have two spaces between the words PRIMARY KEY and the definition of your primary key. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY. You must … Read more
I ended up figuring this out by realizing that I could build a list of coauthor id’s using the template tags that ship with the coauthors plugin. Next, I observed how WordPress core does joins to query by taxonomy, but var_dumping the posts_request on a term archive page. At that point, I just had to … Read more
Use a global. So, your plugin file would look like this: $myConn = new wpdb( ‘username’, ‘password’, ‘database’, ‘localhost’ ); function plugin_step_1( $arg1, $arg2 ) { global $myConn; //code to do stuff here } function plugin_step_2() { global $myConn; // more code here } function plugin_step_3( $arg1 ) { //I don’t need the wpdb object … Read more
Save customizer default values to DB on theme activation
Assuming that all of your sql column names are correct, something like this should work: if(isset($_POST[‘submit’])){ global $wpdb; $tablename= $wpdb . ‘form_subscribe’; $myrows = $wpdb->get_var( $wpdb->prepare(“SELECT email FROM $tablename WHERE email=%s LIMIT 1″, $_POST[’email’])); if(empty($myrows)){ $data=array( ‘name’ => $_POST[‘fullname’], ‘age’ => $_POST[‘age’], ’email’ => $_POST[’email’] ); $wpdb->insert( $tablename, $data); } else { $status=”User already subscribed”; … Read more
Inserting and updating rows with wpdb indreases integer fields by 1 point sometimes
My solution to the problem: $prepare = array(); $in = implode(‘,’, array_fill(0, count($product_ids), ‘%d’)); foreach ($product_ids as $ids){ $prepare[] = $ids; } $prepare[] = “post”; $prepare[] = $num; $results = $this->db->get_results($this->db->prepare(“SELECT ID, post_title FROM {$this->db->posts} WHERE ID NOT IN({$in}) AND post_type=%s ORDER BY ID DESC LIMIT %d”, $prepare));
Object Cache – Avoid db queries totally