Converting mysql to $wpdb

You can query INFORMATION_SCHEMA and achieve the same: function getEnumValues($table, $field) { global $wpdb; $result = $wpdb->get_row(“SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ‘” . DB_NAME . “‘ AND TABLE_NAME = ‘” . $table . “‘ AND COLUMN_NAME LIKE ‘” . $field . “‘”); if($result === FALSE) { die($wpdb->last_error); } // this is the column … Read more

Calculating Bayesian average for custom post type

This is the (updated) code I’m using, which gives results like I’d expect: $args = array( ‘post_type’ => ‘entry’, ‘orderby’ => ‘bayesian_average’, ‘order’ => ‘DESC’, ‘post_status’ => ‘publish’ ); $loop = new WP_Query($args); $number_of_entrants = $loop->post_count; $total_ratings = $total_num_votes = 0; foreach ($loop->posts as $query_post) { $count = $query_post->ratings_count; $average = $query_post->ratings_average; $total_num_votes += $count; … Read more