“The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working

There are two things wrong. First, you have an error in your SQL syntax. The following do not have a type defined: streetaddress NOT NULL, suburbaddress NOT NULL, postcodeaddress NOT NULL, I would assume these are “text” but MySQL doesn’t know that šŸ˜‰ So you probably meant them to be: streetaddress text NOT NULL, suburbaddress … Read more

Problem in creating table through plugin code

The above code should be placed in a function and then hook that with plugin activation hook? Here’s sample structure of plugin-name.php file. Note – Use CREATE TABLE IF NOT EXISTS instead only create table Code Updated on – 2012-08-04 <?php // this code goes into your my_plugin_name.php file function install_my_plugin() { global $wpdb; $table_name … Read more

How to order by blog ID in this multisite ‘List Blogs’ custom function

The following query works. Note the quotes in AND blog_id != ‘1’ global $wpdb; $query = ” SELECT blog_id FROM $wpdb->blogs WHERE site_id = %d AND public=”1″ AND archived = ‘0’ AND mature=”0″ AND spam = ‘0’ AND deleted = ‘0’ AND blog_id != ‘1’ ORDER BY blog_id ASC”; $blogs = $wpdb->get_col( $wpdb->prepare( $query, $wpdb->siteid) … Read more

How to update records using $wpdb?

Logic of my function was all wrong, should have sorted the result in $trans_array before the foreach loop. Here is the updated code that worked, if anyone needs it: function rkm_translation_update() { global $wpdb; $trans_row = $wpdb->get_row(“SELECT * FROM id_item_lid”, OBJECT, 0); $id = $trans_row->id; $item = $trans_row->item_id; $lid = $trans_row->lid; $trans_array = $wpdb->get_results(“SELECT * … Read more

Wpdb query for comment meta for current post

You can join to the comments table and use get_the_ID(): // set the meta_key to the appropriate custom field meta key $meta_key = ‘rating_total’; $ratingtotals = $wpdb->get_var( $wpdb->prepare( ” SELECT sum(cm.meta_value) FROM $wpdb->commentmeta AS cm JOIN $wpdb->comments AS c ON (c.comment_ID = cm.comment_id) WHERE cm.meta_key = %s AND c.comment_post_ID = %d “, $meta_key, get_the_ID() ) … Read more

$wpdb->insert inserting two rows in database

Try something like this function insert_data_into_table () { global $wpdb; $table_name = $wpdb->prefix . “your_table_name”; //Check if table exists if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) : //if not, create the table $sql = “CREATE TABLE ” . $table_name . ” ( (…) ) ENGINE=InnoDB;”; require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’); dbDelta($sql); else: foreach($emails as $mail): $insert = “INSERT … Read more

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