I have JSON objects array as shown below. The following content is in the file (feeds/ptp-ess_landing_house.json) mentioned at Line A.
{
"house_sitting_date_current_month": ["2020-02-01", "2020-02-02", "2020-02-03", "2020-02-04", "2020-02-05", "2020-02-06"],
"house_sitting_date_yes_no_current_month": ["yes", "nada", "nada", "nada", "yes", "yes"],
"house_sitting_date_next_month": ["2020-03-01", "2020-03-02", "2020-03-03", "2020-03-04", "2020-03-05", "2020-03-06"],
"house_sitting_date_yes_no_next_month": ["no", "yes", "yes", "nada", "nada", "nada"],
"toggle_status": null
}
For every particular date there is a value (yes/no/nada) associated with it.
For the current month ($data_house->house_sitting_date_current_month); Feb 1st, Feb 5th and Feb 6th have yes (rest all are nada).
For the next month ($data_house->house_sitting_date_next_month); March 2nd and March 3rd have yes. March 1st is No (rest all are nada).
Here is the php code:
<?php
if (file_exists('feeds/ptp-ess_landing_house.json')) {
$data_house = json_decode(file_get_contents('feeds/ptp-ess_landing_house.json')); // Line A
}
$date = date("Y-m-d");
$sitting_day_str_en = "Sitting day";
$not_a_sitting_day_str_en ="Not a Sitting Day";
?>
<header class="entry-header container">
<?php
the_title('<h1 class="entry-title-house">', '</h1>');
?>
<span class="current-date"><?php echo $date ?></span><!-- prints today's date--> // Line B
<?php if (ICL_LANGUAGE_CODE == 'en') { ?> <!-- English -->
<span class="current-date-answer">Sitting Day</span> // Line C
<?php } ?>
</header>
Problem Statement:
At present I have hard-coded Sitting Day at Line C
I am wondering what changes I should make in the php code above (specially at Line C) so that Line B looks/match/scan ($data_house->house_sitting_date_current_month, $data_house->house_sitting_date_next_month) for a date inside the JSON above
and print content at Line C on the basis of today's date in the JSON.
Case 1: If today's date is 2020-02-1 at Line B and its yes for the corresponding date in the JSON, then it should say Sitting Day at Line C.
Case 2: If today's date is 2020-03-01 at Line B and its no for the corresponding date in the JSON, then it should say Not a Sitting Day at Line C.
Case 3: If today's date is 2020-03-06 at Line B and nada is present in the JSON for that particular date, then it should say display blank/nothing at Line C.
I think, we need to use two foreach loops but more need to be done.
<?php foreach ($data_house->house_sitting_date_current_month as $key1 => $val1) {
foreach ($data_house->house_sitting_date_yes_no_current_month as $key1 => $val1) {
}} ?>
<?php foreach ($data_house->house_sitting_date_next_month as $key2 => $val2) {
foreach ($data_house->house_sitting_date_yes_no_next_month as $key2 => $val2) {
}} ?>