Filtering wordpress comments by votes
Here is my list of recommendations:


To make the database object available in the custom functions' scope, pass it as a parameter.  I know your global declaration is commonly used by WPers, but I consider it to be sloppy development.  If you are going to persist with using global, then you should only do it once per custom function.
In bestanswers() to make your SQL easier to read, use newlines, indentation, spaces around operators, ALLCAPS mysql keywords, double-quoting the full string, and single-quoting the values in the string. *That said, for the most secure and consistent project, you should use prepared statements anytime you are supplying variables to your query.

$results = $wpdb-&gt;get_results(
    "SELECT *
     FROM wp_comments
     LEFT JOIN wp_custom_scoring 
         ON wp_custom_scoring.entryID = wp_comments.comment_ID
     WHERE class = 'point'
         AND comment_post_ID = " . (int)$a . "
         AND type = 'plus'
     GROUP BY entryID
     ORDER BY COUNT(entryID) DESC");

empty() does 2 things.  It checks if a variable !isset() OR loosely evaluates as "falsey". You know that $result will be set because you have unconditionally declared it on the previous line of code. (untested...)

if (!$results)) {
    echo 'Its Empty!';
    return false;
}else{
    return $results;
}


Or if you don't need the echo:

return $results ? $results : false;

In scores(), your $b parameter only determines the WHERE clause, so you can DRY out your code like this:

function score($wpdb, $a, $b) {
    if (in_array($b, ['plus','minus']) {
        $where = "class = 'point' AND type = '{$b}'";
    } else {
        $where = "class = 'fav'";
    }   

    $results = $wpdb-&gt;get_results(
        "SELECT COUNT(id) as total
         FROM wp_custom_scoring
         WHERE entryID = " . (int)$a . "
           AND {$where}";

    if (!$results || !$results[0]-&gt;total) {
        return 0;
    } elseif ($a === 'plus') {
        return "+{$results[0]-&gt;total}";
    } elseif ($a === 'minus') {
        return "-{$results[0]-&gt;total}";
    } else {
        return $results[0]-&gt;total;
    }
}


but again, I urge you to consider using prepared statements as a consistent/stable/secure technique across your whole application.




Ultimately, I don't know what is down in the ...etc. portion of your script, but if you are making two function calls to calculate: score($bests-&gt;comment_ID,"plus") + score($bests-&gt;comment_ID,"minus") &gt; 0, then it may make better sense to create a single custom function that performs this calculation and returns the sum instead.