Issue running db create table query from static method

plugin_dir_url() returns the URL directory path for your plugin, so this won’t work as expected (the function won’t be called): register_activation_hook(plugin_dir_url(__FILE__) . ‘frequentVisitorCoupons.php’, ‘Utilities::createTablesIfNotExists’); You should have used plugin_dir_path() which returns the file-system directory path for your plugin (e.g. /var/www/public/<user>/wp-content/plugins/your-plugin/). But if the code is in the main plugin file, then you could simply use … Read more

Custom array from a query only write the last row of the query

This is because you’re not adding elements to the array. You’re overwriting them: $modified_result = array(); foreach($queryresult as $result){ $modified_result[‘name’] = $result->name; $modified_result[‘address’] = $result->address; } Your loop is setting the name and address property of the $modified_result array directly, and then replacing them for each item in the loop. You want $modified_result to be … Read more

get_results not returning anything

$wpdb->get_results() returns an array on success, so you can’t simply echo $result;. Instead, you can use foreach to loop through the results and display whatever the data that you want to display: $results = $wpdb->get_results( $q ); foreach ( $results as $row ) { echo $row->meta_value . ‘<br />’; } But I can see that … Read more

wpdb COALESCE won’t work

From what I could see, the query did return a result, but the COALESCE() result was not named, hence MySQL and WordPress use the entire COALESCE() query as the field name. To avoid that, you would use an alias for the COALESCE(), e.g. //$query = “SELECT COALESCE( <your queries> ) AS <alias>”; $query = “SELECT … Read more

WPDB: Update table

Now I have learned that the way I change the database is not safe regarding SQL injection. So I wonder where/how did you learn that? And other than that you should check if those two POST variables are actually set, your toggle_status() code looks fine to me, and $wpdb->update() is an easy way to update … Read more

Why does wpdb->update delete other meta?

Your UPDATE command would look like so after all variables are substituted — and in this example, the table prefix is wp_ (the default one), $group[‘1C_id’] is 9095b4cf-969d-11e9-a601-5cf3706390c8, and $found_id (the term ID) is 123. UPDATE `wp_termmeta` SET `meta_key` = ‘1C_id’, `meta_value` = ‘9095b4cf-969d-11e9-a601-5cf3706390c8’ WHERE `term_id` = 123 So that means, all existing meta where … Read more

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