ap_get_vote( integer $post_id, integer $user_id, string|array $type, string $value = '' )
Description #
Get a single vote from database.
Parameters #
- $post_idinteger (Required) Post ID.
- $user_idinteger (Required) User ID.
- $typestring | array (Required) Vote type.
- $valuestring (Optional) Vote value. Default value: ''
Source #
File: includes/votes.php
function ap_get_vote( $post_id, $user_id, $type, $value = '' ) {
global $wpdb;
$where = "SELECT * FROM {$wpdb->ap_votes} WHERE 1=1 ";
if ( ! empty( $type ) ) {
if ( is_array( $type ) ) {
$vote_type_in = sanitize_comma_delimited( $type, 'str' );
if ( ! empty( $vote_type_in ) ) {
$where .= ' AND vote_type IN (' . $vote_type_in . ')';
}
} else {
$where .= $wpdb->prepare( ' AND vote_type = %s', $type );
}
}
if ( ! empty( $value ) ) {
if ( is_array( $value ) ) {
$value_in = sanitize_comma_delimited( $value, 'str' );
if ( ! empty( $value_in ) ) {
$where .= ' AND vote_value IN (' . $value_in . ')';
}
} else {
$where .= $wpdb->prepare( ' AND vote_value = %s', $value );
}
}
$query = $where . $wpdb->prepare( ' AND vote_post_id = %d AND vote_user_id = %d LIMIT 1', $post_id, $user_id );
$vote = $wpdb->get_row( $query ); // phpcs:ignore WordPress.DB
if ( ! empty( $vote ) ) {
return $vote;
}
return false;
}
Expand full source code Collapse full source code View on GitHub: includes/votes.php:417
Add your comment