Home > Net >  I can't solve standings for drivers and constructors from ergast Api
I can't solve standings for drivers and constructors from ergast Api

Time:01-18

I'm using ergast plugin for my wordpress website. The plugin don't have codes for drivers and constructor standings. I'm trying to set not included code but front end don't solve it.

This is the url from ergast: https://ergast.com/api/f1/2021/22/constructorStandings.json

Code for php from plugin:

           case 'constructor_standings':
            
            if(!isset($atts['season'])) {
                $url = 'http://ergast.com/api/f1/current/constructorStandings.json';
            }   elseif(!isset($atts['round'])) {
                $url = 'http://ergast.com/api/f1/'.$atts['season'].'/constructorStandings.json';
            } else {
                $url = 'http://ergast.com/api/f1/'.$atts['season'].'/'.$atts['round'].'/constructorStandings.json';
            }
            
            $data = $this->get_API($url)->MRData->StandingsTable->StandingsLists->ConstructorStandings;
            
            $tbl->addCell('Pos', 'first', 'header');
            $tbl->addCell('Constructor', '', 'header');
            $tbl->addCell('Points', '', 'header');
            $tbl->addCell('Wins', '', 'header');
            
            foreach ($data as $row) {
                $tbl->addRow();
                @$tbl->addCell($row->position);
                @$tbl->addCell($row->name);
                @$tbl->addCell($row->points);
                @$tbl->addCell($row->wins);
            }
            
            break;

Maybe the code went wrong on $data chain, i don't know... Can some where chek my code and solve it, please.

Here is the complete code from plugin project on github: https://github.com/wp-plugins/f1press/blob/master/f1press.php

Regards

CodePudding user response:

Solved! I had to put [0] after StandingLists

$data = $this->get_API($url)->MRData->StandingsTable->StandingsLists[0]->ConstructorStandings;
  •  Tags:  
  • Related