• Resolved jase347

    (@bastelheidi)


    Hi, looks like a great plugin so far!

    I’d like to display the votes count (e.g. in each user’s profile), means the total number an user received on all submissions.

    Is this possible with your plugin or can you help with such (useful) feature?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author TotalSuite

    (@totalsuite)

    Hi @bastelheidi,

    This is not available out of the box. However, we can help you with a small code snippet that can help you achieve that.

    Are you a developer?

    Thread Starter jase347

    (@bastelheidi)

    Hi, thanks!
    That would be great! I’m stuck and cannot retrieve received votes across all of one user’s submissions. I’m starting with learning. Is the table wp_totalcontest_votes existing originally but just empty and all data then within table wp_totalcontest_log?
    I appreciate any help ??

    Plugin Author TotalSuite

    (@totalsuite)

    @bastelheidi Yes. So wp_totalcontest_votes is abandoned.

    What you will need to do is to get the posts that belongs to the user in wp_posts with the post_type=contest_submission

    Each of those contest_submission custom post types have the _tc_votes as a post metadata which represents the number of votes this submission have received, so you will get the sum of the all contest_submissions that belong to the user, sum up the _tc_votes and you are good to go.

    Do you need help in writing that code or can you get that yourself already?

    Thread Starter jase347

    (@bastelheidi)

    Thanks, that helped! Got it to work ??

    function get_total_votes_count($user_id) {
        global $wpdb;
        
        // Query to retrieve the submissions of the given user
        $query = "SELECT p.ID
                  FROM {$wpdb->posts} p
                  INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
                  WHERE p.post_author = %d
                    AND p.post_type = 'contest_submission'
                    AND pm.meta_key = '_tc_votes'";
        
        $submissions = $wpdb->get_col($wpdb->prepare($query, $user_id));
        
        $total_votes_count = 0;
        
        // Calculate the sum of votes for each submission
        foreach ($submissions as $submission_id) {
            $votes_count = get_post_meta($submission_id, '_tc_votes', true);
            $total_votes_count += intval($votes_count);
        }
        
        return $total_votes_count;
    }
    • This reply was modified 1 year, 8 months ago by jase347. Reason: marked as resolved
    Plugin Author TotalSuite

    (@totalsuite)

    This is amazing! ?? Thanks for sharing the code @bastelheidi

    If you have any other questions, please reach out!

    How can I display contestants position on their profile

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Get users’ received votes count’ is closed to new replies.