Created
March 18, 2021 12:41
-
-
Save Alimir/2557874c4e841fc7ecc6dcd3cf6a8cad to your computer and use it in GitHub Desktop.
wp ulike count total likes and dislikes
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 wp_ulike_custom_count_logs( $atts ){ | |
// Global variable | |
global $wpdb; | |
// Default Args | |
$args = shortcode_atts( array( | |
"status" => 'like', | |
"type" => 'post' | |
), $atts ); | |
$table_name = "{$wpdb->prefix}ulike_meta"; | |
$is_distinct = wp_ulike_setting_repo::isDistinct( $args['type'] ); | |
$meta_key_name = sprintf( 'count_%s_%s', $is_distinct ? 'distinct' : 'total', $args['status'] ); | |
$counter_sum = $wpdb->get_var( | |
$wpdb->prepare( | |
"SELECT SUM(`meta_value`) FROM {$table_name} WHERE `meta_key` = '%s' and `meta_group` = '%s'", | |
$meta_key_name, | |
$args['type'] | |
) | |
); | |
return empty( $counter_sum ) ? 0 : (int) $counter_sum; | |
} | |
add_shortcode( 'wp_ulike_custom_count_logs', 'wp_ulike_custom_count_logs' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shorcode examples:
[wp_ulike_custom_count_logs]
[wp_ulike_custom_count_logs type="post" status="dislike"]
[wp_ulike_custom_count_logs type="comment" status="like"]