Using AND and bracket grouping in SQL not working

You need 2 table joins since there are effectively 2 meta keys in your WHERE clause: SELECT DISTINCT SQL_CALC_FOUND_ROWS wp_users.* FROM wp_users INNER JOIN wp_usermeta AS um1 ON (wp_users.ID = um1.user_id) INNER JOIN wp_usermeta AS um2 ON (wp_users.ID = um2.user_id) WHERE (wp_users.user_login LIKE ‘%little%’ OR wp_users.user_email LIKE ‘%little%’ OR wp_users.user_url LIKE ‘%little%’ OR wp_users.display_name LIKE … Read more

Insert Custom Data into wpusers

Never modify the WordPress core table schemas, such as wp_users etc under any circumstances. The next time WordPress changes its tables, your custom columns will be destroyed, and all the data will be deleted. This is unavoidable. Instead, use the User Meta API and table: Retrieving a user meta: $phone = get_user_meta( $user_id, ‘phone_number’, true … Read more

Most commented posts by time period (last 12h, last 24h and etc)

So if you want to get the posts that were commented within the last xx hours, e.g. 12 hours, then try one of the following: Note though, I’m selecting only published posts (post_status=”publish”) and of the post type (post_type=”post”). And just replace the value of $hours with your preferred number of hours. Using TIMESTAMPDIFF(). $hours … Read more

Does WordPress have something like Drupal’s DB API?

Yes, there’s the wpdb class. Some examples can be found for e.g. here. Then there’s the global $wpdb object that contains results and other parts, set based on the current routing. You can also utilize the WP_Query class which is more common. There’s a default global $wp_query object and the $wp_the_query(?) intermediary object, that holds … Read more

CreateOrUpdate in WordPress

If I’m not too badly mistaken, I don’t think there’s a similar method in $wpdb. replace, https://developer.wordpress.org/reference/classes/wpdb/#replace-row, is kind of like that, but not quite as sophisticated I believe. You probably need to build a helper function for that yourself, which wraps update, insert and a bit of logic together. Or use query method with … Read more