Title: Transient
Last modified: August 22, 2016

---

# Transient

 *  [Djib's](https://wordpress.org/support/users/djibs13/)
 * (@djibs13)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/transient/)
 * hello (again)
 * Would it be possible to add support for transients to increase performance?
 * Thank you in advance
 * [https://wordpress.org/plugins/post-share-count/](https://wordpress.org/plugins/post-share-count/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [Djib's](https://wordpress.org/support/users/djibs13/)
 * (@djibs13)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/transient/#post-5193836)
 * 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

Viewing 1 replies (of 1 total)

The topic ‘Transient’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/post-share-count_ffffff.svg)
 * [Post Share Count](https://wordpress.org/plugins/post-share-count/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/post-share-count/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/post-share-count/)
 * [Active Topics](https://wordpress.org/support/plugin/post-share-count/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/post-share-count/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/post-share-count/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [Djib's](https://wordpress.org/support/users/djibs13/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/transient/#post-5193836)
 * Status: not resolved