SELECT from wp_users, get Displayname too

You will need to do a JOIN on the users table in your old database, and also select the display name. One key thing to note here, is that I aliased dbold_posts as P, and dbold_users as U – when dealing with multiple table, it’s always best practice to specify which table you are referring … Read more

$wpdb->get_var – What value is returned when zero records are found?

First, you’re using prepare() wrong. Should be this: $wpdb->prepare(“SELECT Active FROM testers WHERE user_id = %s”, $user_id) Or even better (%d) represents numeric value as oppose to %s which is string: $wpdb->prepare(“SELECT Active FROM testers WHERE user_id = %d”, $user_id) If you have any debugging enabled, it will throw an error from your code. Which … Read more

mySQL queries are executed twice on wordpress website

The use of wpdb->insert and wp_insert_post both accomplish an SQL Insert, which is why you’re seeing 2 records each time. You must use only one instance of an insert method, and then Pass $my_post to WP_Query CLARIFICATION As Milo points out in his comment wpdb->insert will insert into any table, while wp_insert_post is used to … Read more

wpdb getting avatars and author url

You just need to return the user ID in the main select and use that as the author ID. Also I probably confused the issue previously by using echo with commas (separate arguments) rather than dots (one concatenated argument). $weekly = $wpdb->get_results ( ” SELECT u.ID, ( SELECT CONCAT_WS(‘.’, SUM(CASE WHEN p.post_date > ‘$date2’ THEN … Read more

WPDB SQL Ignore `post_status` Parameter

Well, first of all, you use where post_status=”publish”. So you wouldnt need to explicitly tell the drafts not to show up by using wp_posts.post_status != ‘draft’ I think, your SQL says somthing like: Grab all posts which are published and not drafted and attached to term_id 17 OR grab all posts which are attached to … Read more

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