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

mysql query – how to escape apostrophe?

Use esc_html() when outputting a string value inside tags. Use esc_attr() when you’re outputting a string value inside an attribute=””. If you’re outputting a URL, use esc_url() instead of those two. if ($tenantsInfo) { foreach ($tenantsInfo as $tenant) { echo “<h2>Welcome, ” . esc_html( $tenant->tenant_name ) . “</h2>”; } }

Valid SQL query return empty

There are view issues with the query: First what the @janh wrote. Second why you removing the am/pm when you could easily use the date(“Y-m-d H:i:s”); Third, there is this little helper for the database table prefixes $wpdb->prefix Users table the column name is display_name Also when you make aliases is a good rule to … Read more

Cannot access $wpdb, comes back NULL

As stated in the Comments, do not access a plugin file directly. Instead, use other means that incorporate the REST API or the included Ajax functionality in WordPress. To learn how to use Ajax in your Plugin, have a look here: Ajax in Plugins

Need help converting get_user_meta [keys] into own array

You have to return the keys from array with this: $keys = array_keys($all_meta_for_user); Afterwards, implode your array to a string (inserting a dot before to create the first class): $stringedKeys=”.”.implode(‘,.’, $keys); And now you have a string of keys that you can use in JS if you like, or insert them from PHP directly.

Get unique results from this function

It would likely be more efficient to change your database query to SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = ‘wc_billing_field_3465’

Query Column of Specific ID from Database Table

You have 2 two problems here: – You can’t use $wpdb-> with custom tables because [postmeta, posts, …] are variables in the class $wpdb. – WHERE ‘id’= 2 is not correct WHERE id = 2 So it should work: global $wpdb; $table_name = “_customtable”; $retrieve_data = $wpdb->get_results( “SELECT * FROM $table_name WHERE id = 2” … Read more

how to connect to another database in wordpress

Look at the order of the constructor arguments in the documentation: string $dbuser, string $dbpassword, string $dbname, string $dbhost You’ve got the arguments in the wrong order. Move the host to the end: $newconnection= new wpdb(“username”,”password”,”databasename”,”localhost”);

Generating a perfect loop

That’s because you’re looping twice due to the while. Completely unecessary. foreach ($orders_ids as $details) { $order = wc_get_order($details->order_id); $fornavn = $order->get_billing_first_name(); $etternavn = $order->get_billing_last_name(); $deltakerkategori = $order->get_meta( ‘_billing_field_447’, true ); $deltakerradio = $order->get_meta( ‘_billing_field_538′, true ); echo ”.$fornavn.’ ‘.$etternavn.’ ‘.$deltakerkategori.”https://wordpress.stackexchange.com/”.$deltakerradio.'<br>’; } Additionally, if that doesn’t fix it due to…well, magic, try this patch: foreach( … Read more

Delete database record using plugin from admin panel

OK, so your code can’t work, because you use $wpdb->delete incorrectly. Let’s take a look at Codex. $wpdb->delete takes 3 params (one is optional): $table (string) (required) Table name. Default: None $where (array) (required) A named array of WHERE clauses (in column -> value pairs). Multiple clauses will be joined with ANDs. Both $where columns … Read more

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