First, you’ll need to set up a WordPress cron job, and take note of its shortcomings…
Using the Codex example, this is a structure of how this could be done:
add_action( 'my_daily_event', 'do_this_daily' );
add_action( 'wp', 'my_activation' );
function do_this_daily()
{
// 1) Use get_posts to retrieve your Post Type
// 2) Iterate through the resulting posts and grab the Facebook Page custom field of each post
// 3) Request FB Graph info as follows
$fb = wp_remote_get( 'https://graph.facebook.com/Stack-Exchange', array( 'timeout' => 120, 'httpversion' => '1.1' ) );
if ( $fb['response']['code'] == '200' )
{
$fb_array = json_decode( $fb['body'], true );
echo '<pre>' . print_r( $fb_array, true ) . '</pre>';
}
// 4) Update the Likes custom field of each post with $fb_array['likes'] value
}
function my_activation() {
if ( !wp_next_scheduled( 'my_daily_event' ) ) {
wp_schedule_event( time(), 'daily', 'my_daily_event' );
}
}