0

I am tasked with taking these two APIs:

https://api.secondharvestvfd.com/v1/banks/1/drives/392/teams/397

https://api.secondharvestvfd.com/v1/banks/1/drives/392/teams/399

Calculating the result of team_raised * bank_meals_to_dollar from both, adding them together and outputting the result in a ticker on a wordpress site.

I've got no idea how to start.

Would it be a matter of writing some PHP to create API Shortcodes in order to perform the multiplication and addition?

1 Answer 1

1

You can use Curl with php in wordpress Code :

<?php 

function getApi($url){
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);


$response_ = json_decode($response, true);
return $response_;

}

$respon_1 = getApi("https://api.secondharvestvfd.com/v1/banks/1/drives/392/teams/397");
$team_raised_1 = floatval($respon_1['team_raised']);
$bank_meals_to_dollar_1 = floatval($respon_1['bank_meals_to_dollar']);
$result_1 = $team_raised_1 * $bank_meals_to_dollar_1;


$respon_2 = getApi("https://api.secondharvestvfd.com/v1/banks/1/drives/392/teams/399");
$team_raised_2 = floatval($respon_2['team_raised']);
$bank_meals_to_dollar_2 = floatval($respon_2['bank_meals_to_dollar']);
$result_2 = $team_raised_2 * $bank_meals_to_dollar_2;
$value_tot = $result_2 + $result_1;
echo $value_tot;
Sign up to request clarification or add additional context in comments.

4 Comments

There are WordPress functions for remote get wordpress.stackexchange.com/questions/93991/…
@Alaa can you message me - [email protected]
this works and displays properly but it breaks the page. I'm inserting it using shortcode plugins. Do you think it would be worth implementing it by creating my own shortcode or placing it directly in the php of the page?
if know the place of the file where you wanna display it ,it will be more easy by implementing it manually .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.