php - Update sub fields from repeater with different values in WordPress ACF

880

I'm trying to update 4 different sub fields from a repeater with 4 different values that i get from a json.

The thing is i'm able to update all the sub fields with a single value(the same for all 4 sub fields), but not with different values.

What I have is: (Sorry i dont know how to add php to the snippet)

Code Link: Link

I've created also an array of the different urls..

$counter = 0; if(have_rows('branch','option')): while(have_rows('branch','option')): the_row();

      $ch = curl_init();
      
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($ch, CURLOPT_URL, 'https://www.worldtimeapi.org/api/timezone/Asia/Kuala_Lumpur.json');
      $result = curl_exec($ch);
      curl_close($ch);

      $obj = json_decode($result);
      $value = $obj->utc_offset; 
      
      update_sub_field('timezone', $value); ?>


        <div class="clock-wrapper" data-timezone="<?php the_sub_field('timezone'); ?>">

I have 4 different values I got from the URL:

worldtimeapi.org/api/timezone/Europe/London.json
worldtimeapi.org/api/timezone/Australia/Perth.json
worldtimeapi.org/api/timezone/Europe/Madrid.json

How could I give to each sub field one of the values?

People are also looking for solutions to the problem: javascript - Inactive/browser close - change status to 0 and back to 1 when user returns

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.