Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created August 14, 2023 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everaldomatias/48521edf7354caa8a6423a355916f5fc to your computer and use it in GitHub Desktop.
Save everaldomatias/48521edf7354caa8a6423a355916f5fc to your computer and use it in GitHub Desktop.
Get vote count
<?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