Получить ценовое отношение валюты - PullRequest
0 голосов
/ 21 ноября 2018
I want to get price which is stored in database already. Here is my code to get the prices with respect of currencies. I just got the currencies but how will I find all the prices from that loop. I need some help. Please help me out.

Я упомянул здесь весь код, откуда пришли валюты, и функцию сохранения цен.

Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне. Мне нужна помощь.Пожалуйста, помогите мне.

    add_action( 'init', 'process_api' );

function process_api() {
  //api hit

$ch = curl_init();
$api_expiry = get_option("api_expiry");
$endpoint = 'convert';
$access_key = 'be26e1bc17e9426b149a653f07715847';

  if (strtotime(date($api_expiry)) <= strtotime(date("Y-m-d")) ) // Expired
  {

    $curr_arg = array('post_status'=>'publish','post_type' => 'price_compare', 'orderby' => 'date','order' => 'ASC', 'numberposts' => -1);
    $curr_return = get_posts($curr_arg);
    foreach ($curr_return as $loc_curr_key => $loc_curr_value) {
        $currencies[] = get_post_meta($loc_curr_value->ID, 'meta_box_text', true);
    }

    $curr_no = count($currencies);

    foreach ($currencies as $key => $currency) {
        for ($i=0; $i < $curr_no ; $i++) { 
          $curr_key = strtolower($currency."_".$currencies[$i]);

          $url = 'http://apilayer.net/api/'. $endpoint . '?access_key=' . $access_key .'&from=' . $currency . '&to=' . $currencies[$i] . '&amount=1' ;
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
          $return = curl_exec($ch);
          $decoded = json_decode($return);

          $curr_price = round($decoded->result,2);


          update_option($curr_key,$curr_price);


        }


    }

    $api_expiry = date('Y-m-d', strtotime("+1 day"));
    update_option("api_expiry",$api_expiry);

  } 

  $curr_search = array('post_status'=>'publish','post_type' => 'price_compare', 'orderby' => 'date','order' => 'ASC', 'numberposts' => -1);
    $curr_result = get_posts($curr_search);
    foreach ($curr_result as $curr_search_key => $curr_search_val) {
        $currencies[] = get_post_meta($curr_search_val->ID, 'meta_box_text', true);
    }

    $curr_no = count($currencies);

    foreach ($currencies as $key => $currency) {
        for ($i=0; $i < $curr_no ; $i++) { 

          echo $curr_key = strtolower($currency."_".$currencies[$i]);
          $curr_search = array_search($curr_price, $curr_key);
          echo $curr_search;

        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...