Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //FACEBOOK
- function insert_facebook_likes_custom_field($post_ID) {
- global $wpdb;
- if(!wp_is_post_revision($post_ID)) {
- add_post_meta($post_ID, 'fb_likes_count', '0', true);
- }
- }
- add_action('publish_page', 'insert_facebook_likes_custom_field');
- add_action('publish_post', 'insert_facebook_likes_custom_field');
- add_action( 'fb_hourly_count', 'do_this_hourly' );
- add_action( 'wp', 'fb_activation' );
- function do_this_hourly() {
- $args=array(
- 'post_type' => 'post',
- 'post_mime_type' => '',
- 'post_status' => 'publish'
- );
- $posts_array = get_posts( $args );
- foreach($posts_array as $post):
- $permalink = get_permalink($post->ID);
- $idpost = $post->ID;
- $data = file_get_contents('http://graph.facebook.com/?id='.$permalink);
- $json = $data;
- $obj = json_decode($json);
- $like_no = $obj->{'shares'};
- $meta_values = get_post_meta($idpost, 'fb_likes_count', true);
- if($like_no == null){$like_no = 0;}
- update_post_meta($idpost, 'fb_likes_count', $like_no, false);
- endforeach;
- }
- add_action('init', 'do_this_hourly');
- function fb_activation() {
- if ( !wp_next_scheduled( 'fb_hourly_count' ) ) {
- wp_schedule_event( time(), 'hourly', 'fb_hourly_count' );
- }
- }
- /* End of fb like count management */
- // END FACEBOOK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement