How can I migrate mysql_fetch_array to $wbpdb?

You didn’t need to post all that code to wade through! The problem is here: <?php global $wpdb; function get_tag_data2() { You need to global inside the function – that’s the point of global: <?php function get_tag_data2() { global $wpdb; // Original function code }

writing inner join in wpdb

thanks for your time and thanks to @czerspalace I started the query with double quotation and then separate it with a single quotation and after looking at the echo output I found that there’s no spaces between From and table name this is the correct way $pending_reservations = $wpdb->get_results(‘ SELECT booking_calendars.cal_name FROM ‘.$wpdb->prefix.’booking_calendars AS booking_calendars … Read more

$wpdb->insert is not working

It sounds like it would be simpler to go back and fix your initial try: saving an option to a WP-native table rather than creating your own. Try update_option – it creates an option if it doesn’t exist, or updates if it does. This will save you a lot of code and headaches in the … Read more

$wpdb->insert query changes to SHOW COLUMNS query Output

For anyone else finding this question. WordPress seems to do a SHOW FULL COLUMNS query before executing the INSERT query. If it determines that the INSERT query would fail/store bad data, for example because the given data types would not fit in the column, it does not execute the insert query at all and return … Read more

Show last modified date of database

There’s an UPDATE_TIME column in the TABLES table in the information_schema database. So you can try to get the max from that column with e.g.: SELECT MAX(`UPDATE_TIME`) FROM information_schema.TABLES WHERE TABLE_SCHEMA = ‘dbname’ where we replace ‘dbname’ with the corresponding database name. More related info here on SO. From the MySQL 5.7 docs: UPDATE_TIME displays … Read more

How to correctly pass values to wpdb->prepare()?

I’ve found an answer by myself.. (sample code) $args_array = array($post_type); $term_slugs = array(‘foto’, ‘video’); // create a string like ‘%s, %s’ ecc $placeholders = implode(‘, ‘, array_fill(0, count($term_slugs), “%s”)); $term_query = “t.slug IN ($placeholders) “; $args_array = array_merge($args_array, $term_slugs); $ids = $wpdb->get_results($wpdb->prepare(” SELECT m.meta_value FROM ” . $wpdb->prefix . “posts p INNER JOIN ” … Read more

How to Fetch values from WP database based on selected option value by onchange using PHP?

You can use below example to use Ajax in wordpress. This article explains it quite nicely. Main jquery function to use wp_enqueue_script( ‘ajax-scripts’, url-to-your-file/plugin-ajax.js’, __FILE__ ) , array( ‘jquery’ ), ‘1.0.0’, true ); jQuery(function($) { $(document).ready(function(){ $(‘#mySelect’).on( ‘change’ , function(){ var newValue = $(this).val(); $.ajax({ type: ‘POST’, url: ajaxurl, // use ajax_params.ajax_url if using in … Read more

Converting MYSQL to WordPress $WPDB

The root problem here is the assumption that WordPress deals in mysql functions and mysql objects, and that knowledge of these functions is helpful. The truth is, this is a complete API in of itself, and so the assumptions that knowledge of mysql_ functions provides are not useful or relevant beyond the syntax of SQL. … Read more

WPDB Update using Conditional Arrays

This is not posible with $wpdb->update(). If you check the source code, you will see these lines (lines 2150 – 2161), there is no way getting an OR in there: foreach ( $where as $field => $value ) { if ( is_null( $value[‘value’] ) ) { $conditions[] = “`$field` IS NULL”; continue; } $conditions[] = … Read more

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