greatest() function returns undefined property

I think you want to use get_var(), not get_row() – looking at the documentation, MySQL’s GREATEST just returns a single value. $results will then just be the value of the greatest (be it up or down). If you want the greatest up and the greatest down, use; $wpdb->get_row(“SELECT GREATEST(up) AS ‘up’, GREATEST(down) AS ‘down’ …”)

query users by role

You can use this function: // get users with specified roles function getUsersWithRole( $roles ) { global $wpdb; if ( ! is_array( $roles ) ) $roles = array_walk( explode( “,”, $roles ), ‘trim’ ); $sql=” SELECT ID, display_name FROM ” . $wpdb->users . ‘ INNER JOIN ‘ . $wpdb->usermeta . ‘ ON ‘ . $wpdb->users … Read more

How to create another version of my site based on the same database

There are a couple of ways you can achieve what you asked for but the latter is what I’d recommend: Set up a copy of the site in a different directory and using your web host’s control panel map the different domains to the appropriate directories. Use the same DB_NAME/DB_USER/DB_PASSWORD/DB_HOST in the /wp-config.php file for … Read more

Does WordPress ever need multiple databases?

could a WordPress installation get so large or gain so many users that it needs another database? If you mean sharding of a database to spread data across multiple servers for sheer quantity of data, then yes, but only for 3 or 4 websites in existence, aka WordPress.com. If you think you need this for … Read more

How to remove duplicate Custom Fields?

You can delete directly from the database, using an SQL statement like: delete from wp_postmeta where meta_id in ( select * from ( select meta_id from wp_postmeta a where a.meta_key = ‘blogger_blog’ and meta_id not in ( select min(meta_id) from wp_postmeta b where b.post_id = a.post_id and b.meta_key = ‘blogger_blog’ ) ) as x ); … Read more