How to search usermeta table

This works: $WhoIsUser = get_users( array( ‘meta_key’ => ‘deviceid’, ‘meta_value’ => ‘45545’ ) ); This returns the whole row for that user from the users table. If you print_r it out like so: echo ‘<pre>’ echo print_r($WhoIsUser, TRUE); echo ‘</pre>’ you get: Array ( [0] => WP_User Object ( [data] => stdClass Object ( [ID] … Read more

Delete oldest wordpress post (SQL query)

I figured it out! Pretty simple actually.. You can replace post_date_gmt with ID depending on your needs. post_author != 1 will prevent the admin’s post from being deleted, so the menu links and pages will stay intact 🙂 function deleteOldestPost(){ global $wpdb; $prefix = $wpdb->prefix; $wpdb->query(“DELETE FROM “.$prefix.”posts where post_author != 1 order by post_date_gmt … Read more

How to optimize and reduce excessive database queries

You can use a combination of caching plugin and appropriately coded themes and plugins to cache query results and speed things up. Yes, eventually if you are running many queries, a site can get bogged down. This typically happens when query-intensive themes or plugins are used. To start investigating your own site’s queries, there are … Read more

Passing Current User ID into SQL statement

No need to use []… just use simple single quotations (also no quotations does the job): $sql =” SELECT … WHERE wp_users.`ID` = ‘$userID'”; OR $sql =” SELECT … WHERE wp_users.`ID` = $userID”;