Get price respect of currency
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.
I mentioned here all the code from where the currencies came and the prices store function.
I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.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;
}
}
}
wordpress custom-post-type
|
show 1 more comment
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.
I mentioned here all the code from where the currencies came and the prices store function.
I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.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;
}
}
}
wordpress custom-post-type
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50
|
show 1 more comment
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.
I mentioned here all the code from where the currencies came and the prices store function.
I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.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;
}
}
}
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.
I mentioned here all the code from where the currencies came and the prices store function.
I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.I need some help. Please help me out.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;
}
}
}
wordpress custom-post-type
wordpress custom-post-type
edited Nov 21 '18 at 7:56
Abhijit Dutta
asked Nov 21 '18 at 7:39
Abhijit DuttaAbhijit Dutta
62
62
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50
|
show 1 more comment
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407285%2fget-price-respect-of-currency%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407285%2fget-price-respect-of-currency%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
can't see where are you getting the price from
– line88
Nov 21 '18 at 7:46
$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]);
– Abhijit Dutta
Nov 21 '18 at 7:49
$url = '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);
– Abhijit Dutta
Nov 21 '18 at 7:49
Price is coming from the api and update it in wp_options table
– Abhijit Dutta
Nov 21 '18 at 7:49
you should post it all in the question, it's unreadable from the comment section
– line88
Nov 21 '18 at 7:50