• I’m sure this looks horrible, but it is my first time doing a custom query using $wpdb

    I am trying to grab the total values from a meta_value in the commentmeta table assigned a specific post id with a specific meta_key of ‘rating’.. but I’m not sure what I’m doing wrong.. here is my code

    <?php
    			global $wpdb;
       			$rating = $wpdb->get_var("
       				SELECT SUM($wpdb->commentmeta.meta_value)
       				FROM $wpdb->posts, $wpdb->commentmeta, $wpdb->comments
       				WHERE $wpdb->posts.ID='46'
       				AND $wpdb->commentmeta.meta_key='rating'");
    
       				echo $rating;
    			?>
Viewing 1 replies (of 1 total)
  • Thread Starter Sarah_Frantz

    (@sarah_frantz)

    OR is it because I need to match up the comments table with the commentmeta table and then match it up to the posts table?

Viewing 1 replies (of 1 total)
  • The topic ‘Custom $wpdb queries.. need help’ is closed to new replies.