ap_count_post_votes_by( string $by, string $value )
Description #
Count votes of a post and property format.
Parameters #
- $bystring (Required) By.
- $valuestring (Required) Value.
Source #
File: includes/votes.php
function ap_count_post_votes_by( $by, $value ) {
$bys = array( 'post_id', 'user_id', 'actor_id' );
if ( ! in_array( $by, $bys, true ) ) {
return false;
}
$new_counts = array(
'votes_net' => 0,
'votes_down' => 0,
'votes_up' => 0,
);
$args = array(
'vote_type' => 'vote',
'group' => 'vote_value',
);
if ( 'post_id' === $by ) {
$args['vote_post_id'] = $value;
} elseif ( 'user_id' === $by ) {
$args['vote_user_id'] = $value;
} elseif ( 'actor_id' === $by ) {
$args['vote_actor_id'] = $value;
}
$rows = ap_count_votes( $args );
if ( false !== $rows ) {
foreach ( (array) $rows as $row ) {
if ( is_object( $row ) && isset( $row->count ) ) {
$type = '-1' == $row->vote_value ? 'votes_down' : 'votes_up'; // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
$new_counts[ $type ] = (int) $row->count;
}
}
$new_counts['votes_net'] = $new_counts['votes_up'] - $new_counts['votes_down'];
}
return $new_counts;
}
Expand full source code Collapse full source code View on GitHub: includes/votes.php:367
Add your comment