Created
August 14, 2023 21:37
-
-
Save everaldomatias/48521edf7354caa8a6423a355916f5fc to your computer and use it in GitHub Desktop.
Get vote count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_vote_count ( $post_id ) { | |
$args = [ | |
'post_type' => 'vote', | |
'fields' => 'ids', | |
'meta_query' => [ | |
[ | |
'key' => 'voting_id', | |
'value' => $post_id, | |
'compare' => '=', | |
'type' => 'NUMERIC' | |
], | |
] | |
]; | |
$query = new \WP_Query( $args ); | |
$votes = count( $query->posts ); | |
return $votes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment