Getting the “Thank You Button” count from anywhere on you blog

I’ve been working on rebuilding my website, that is my portfolio and blog, and wanted to try out something like a “Thank You” button. I’ve managed to find this neat plugin that does just that. It’s nice that it’s customizable for the average user and for those of us for which that’s just not enough, well… we can always meddle around the plugin’s PHP files. I’ve customized my button nice and well, but didn’t find a way to access the “Thank You” count for a certain post from anywhere on my website. Vladimir Garagulya from Shine PHP was kind enough to show me the query for doing just that and fter wrapping it in a function I came up with this:

function getThankYouCount($postID){
    global $wpdb;
    $thankYouCount= $wpdb->get_row("select quant from wp_thanks_counters where post_id=$postID");
    if( $thankYouCount){
        return $thankYouCount->quant;
    }
    else{
        return 0;
    }
}

Just place it in your functions.php file and you will, of course, have to replace the WP part from the wp_thanks_counters table with your own table prefix. If anyone has better solutions for this issue, feel free to share. Cheers!