update_term_meta()无法正常工作

时间:2018-08-14 10:25:11

标签: php database wordpress

我正在尝试创建一个cron作业,该作业将写入DB并在每个不同的行上存储新值和上一个值。但是无论如何,每次cron作业完成时,两个值都是相同的(减小并成比例地增加)。这是代码:

function getytdata() {

 global $wpdb;

 $ids = $wpdb->get_results('SELECT term_id, meta_value FROM ' . $wpdb->prefix . 'termmeta WHERE meta_key =\'channelid\'' );

 $api_key = "###";

  foreach ($ids as $id) {

   $channel_id = $id->meta_value;
   $channel_bd_id =  $id->term_id;

   $api_response = file_get_contents('https://www.googleapis.com/youtube/v3/###');
   $api_response_decoded = json_decode($api_response, true);

   //subscriberCount

   $current = $api_response_decoded['items'][0]['statistics']['subscriberCount'];
   $yesterday =  get_term_meta( $channel_bd_id, 'subscribers', true );

   update_term_meta($channel_bd_id , 'subsyesterday', $yesterday);
   update_term_meta($channel_bd_id , 'subscribers', $current);
   }
}

0 个答案:

没有答案