首先,您需要设置WordPress cron作业,并注意its shortcomings...
使用法典example, 这是一个如何做到这一点的结构:
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\' );
}
}