Skip to content

Instantly share code, notes, and snippets.

@Alimir
Created June 22, 2021 07:45
Show Gist options
  • Save Alimir/dac482e726ced8c77d230d8327804e7e to your computer and use it in GitHub Desktop.
Save Alimir/dac482e726ced8c77d230d8327804e7e to your computer and use it in GitHub Desktop.
Get number of likes received by post author
<?php
function wp_ulike_custom_author_counter( $user_id, $status = 'like' ){
global $wpdb;
$meta_key = wp_ulike_setting_repo::isDistinct( 'post' ) ? 'count_distinct_' . $status : 'count_total_' . $status;
return $wpdb->get_var(
$wpdb->prepare(
"SELECT SUM(m.meta_value) FROM {$wpdb->prefix}ulike_meta m INNER JOIN $wpdb->posts p ON m.item_id = p.ID AND p.post_author = %s WHERE m.meta_group = 'post' AND m.meta_key = %s",
$user_id,
$meta_key
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment