Support » Plugin: Site Reviews » How to make a list of most active users?

  • Resolved vidalpt

    (@vidalpt)


    Amazing Plugin all the time!

    Is there a way to make a list of most active users with the number of review that they left?
    I’d like to give some compensation to them. Top 10 users of this month, for example.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    You could do something like this:

    global $wpdb;
    
    $authors = $wpdb->get_results("
        SELECT u.ID, u.display_name, COUNT(*) as reviews
        FROM {$wpdb->users} AS u 
        INNER JOIN {$wpdb->posts} AS p ON p.post_author = u.ID 
        WHERE p.post_status = 'publish'
        AND p.post_type = 'site-review'
        GROUP BY u.ID
        ORDER BY reviews DESC
        LIMIT 10
    ");
    
    // print results to the page
    glsr_debug($authors);
    
    foreach ($authors as $author) {
        glsr_debug(
            sprintf('%s has submitted %d reviews', $author->display_name, $author->reviews)
        );
    }
    

    Alternatively, you could do this instead:

    global $wpdb;
    
    $authors = $wpdb->get_results("
        SELECT post_author as user_id, COUNT(*) as reviews
        FROM {$wpdb->posts} 
        WHERE post_status = 'publish'
        AND post_type = 'site-review'
        GROUP BY post_author
        ORDER BY reviews DESC
        LIMIT 10
    ");
    
    // print results to the page
    glsr_debug($authors);
    
    foreach ($authors as $author) {
        $authorName = get_the_author_meta('display_name', $author->user_id);
        glsr_debug(
            sprintf('%s has submitted %d reviews', $authorName, $author->reviews)
        );
    }
    Thread Starter vidalpt

    (@vidalpt)

    it works well!! Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make a list of most active users?’ is closed to new replies.