Why $wpdb->show_errors() and print_error() is showing an output even if the query output is correct?

In order of figuring out the following issue, see https://wordpress.stackexchange.com/questions/178995/sanitize-a-working-query-string-by-using-wpdb-prepare-fails-with-mysql-db-er i ran into an rather odd behaviour. Even that my used query was correct and showing the right output. global $wpdb; $wpdb->show_errors(); $pageposts = $wpdb->get_results( $wpdb->prepare( ” SELECT skposts.* FROM $wpdb->posts skposts, $wpdb->postmeta skpostmeta1, $wpdb->postmeta skpostmeta2 WHERE skposts.ID = skpostmeta1.post_id AND skposts.ID = skpostmeta2.post_id AND … Read more

How to programatically change username (user_login)?

As in the title, how to programatically change user’s login? I wanted to use wp_insert_user function, but it appears that when updating current user, it doesn’t change their username. Should I use $wpdb->update for that? If yes, how would code for changing username look like? What consequences would changing user login have, given that WordPress … Read more

get_results using wpdb

I’m trying to retrieve information on my database. I wanted to display all pages using this statement, but I’m getting a blank ARRAY global $wpdb; $result = $wpdb->get_results ( ” SELECT * FROM $wpdb->wp_posts WHERE post_type=”page” ” ); echo $result; // display data Output: ARRAY EDIT: After changing below suggestions, I’m now using this. but … Read more

Is it mandatory to use $wpdb->prefix in custom tables

Sorry if this question is trivial. I’m just beginning to develop plugins in WordPress. In all the tutorials I found this: while creating the custom tables, $wpdb->prefix is used. Example: $table_name = $wpdb->prefix . “liveshoutbox”; My question: Is it mandatory to use $wpdb->prefix? What happens If I don’t use prefix for my custom tables? 2 … Read more

Showing errors with $wpdb update

I am using $wpdb->update to update a custom table I have in my database. When I var_dump the result it returns: int(0) So I tried $wpdb->print_error() to see what’s wrong. However, it shows nothing. I also tried $wpdb->show_errors(), but again it showed nothing. The wpdb docs don’t go into much detail on how to use … Read more