我已经完成了,下面是完整的代码:
function insert_facebook_likes_custom_field($post_ID) {
global $wpdb;
if (!wp_is_post_revision($post_ID)) {
add_post_meta($post_ID, \'likes_count\', \'0\', true);
}
}
add_action(\'publish_page\', \'insert_facebook_likes_custom_field\');
add_action(\'publish_post\', \'insert_facebook_likes_custom_field\');
function update_facebook_likes($content = \'\') {
global $wp_query;
$permalink = get_permalink();
$idpost = $wp_query->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, \'likes_count\', true);
if ($like_no == null) {
$like_no = 0;
}
update_post_meta($idpost, \'likes_count\', $like_no, false);
return $content;
}
add_action(\'the_content\', \'update_facebook_likes\');
只需将此代码复制/粘贴到函数中即可。php。数据将存储在名为likes\\u count的自定义字段中。希望有帮助