Thread Starter
Djib's
(@djibs13)
I modified the function to use the transients:
function get_the_post_share_count( $post = 0, $services, $time = 3600, $max_sync = 1 ) {
$count = get_transient( 'post_share_count-' . $post->ID );
static $updated = 0;
$post = get_post( $post );
$id = isset( $post->ID ) ? $post->ID : 0;
$count['total'] = ( isset( $post->post_share_total_count ) ) ? $post->post_share_total_count : 0;
if ( isset( $post->post_share_count ) && is_array( $post->post_share_count ) )
$count = array_merge( $count, $post->post_share_count );
if ( ( ! isset( $post->post_share_last_sync ) || $post->post_share_last_sync < ( time() - $time ) ) && $updated < $max_sync) {
$updated_counters = post_share_count_sync_post( $id, $services );
update_post_meta( $id, 'post_share_last_sync', time() );
if ( ! empty( $updated_counters ) ) {
update_post_meta( $id, 'post_share_count', $updated_counters );
if ( $total = array_sum( $updated_counters ) ) {
update_post_meta( $id, 'post_share_total_count', $total );
$updated_counters['total'] = $total;
}
$count = $updated_counters;
}
$updated++;
}
set_transient( 'post_share_count-' . $post->ID, $count, $time );
return apply_filters( 'the_post_share_count', $count, $id );
}
and in my theme I take the data from transient
<?php $tableau_count = get_transient('post_share_count-' . $post->ID);
echo $tableau_count['twitter'];
//and / or
echo $tableau_count['facebook'];
//and / or
echo $tableau_count['googleplus'];
//and / or
echo $tableau_count['total'];
?>
I’m not a developer so I do not know if there is a better solution, but it’s works