获得货币的价格尊重

时间:2018-11-21 07:39:52

标签: wordpress custom-post-type

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;

        }
    }
}

0 个答案:

没有答案