Filter results from a serialized string to use on statistics

So basically the form saves a large serialized array in the database. Now since you have multiple forms, you need to iterate over the result from get_results, unserialize the column and then access the city key. global $wpdb; $table_name = $wpdb->prefix.’db7_forms’; $results = $wpdb->get_results( “SELECT form_value FROM $table_name WHERE form_post_id = 6062”, OBJECT ); // … 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 ) ); }

External wpdb connections in different plugins on single page

You’ll have to make the variable global when you define it, e.g. global $mydb; $mydb = new wpdb(‘username’,’password’,’database’,’localhost’); and then use global $mydb; in the other plugins. Aside from theme files, functions.php, and plugins while being loaded, pretty much nothing in WP runs in global context, so if you need to access global variables, you’ll … Read more

How to make multi site with single Database?

First off please note that although you plan to use different themes and plugins, your core content is identical, so search engines can and will figure out that all of these sites contain the same content. So if you proceed, just know that you won’t be bringing in much if any organic traffic. Perhaps there … Read more

Wpdb get->results to out the the month from the db

You could use the MONTHNAME(dato) on your select Like $rows = $wpdb->get_results( “SELECT MONTHNAME(dato) as month_name, avg(fiske_vaegt) as fiske_vaegt FROM `wp_registreringer` WHERE MONTH(dato) = 11 AND YEAR(dato) = 2017;”); and access it like this echo $row->month_name

Wpdb->query result show 1 but is not an integer

I found the solution. The result 1 for my query means true and it’s a boolean so $wpdb->query can return true, not only int|false as it is written above the public function query : wpdb::query PHP code $res = $wpdb->query(“ALTER TABLE ” . $table_name. ” ADD ” . $column_name . ” varchar(35)”); error_log( $res ); … Read more