Title: transient api json shortcode
Last modified: August 9, 2018

---

# transient api json shortcode

 *  [paulbuscano003](https://wordpress.org/support/users/paulbuscano003/)
 * (@paulbuscano003)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/transient-api-json-shortcode/)
 * Hi,
 * I want to transient my API can anyone please help me with my problem.
 * Please see my sample code below.
 *     ```
       //league-leaders
       function test_api_leaders_shortcode( $atts , $content = null){
         // Attributes
         $atts = shortcode_atts(
           array(
                   'comid' => '16395',
                   'statistic' => 'sPointsAverage',
           ),
           $atts,
           'test-api-leaders'
         );
   
       $competition = $atts['comid'];
   
       $statisticsz = $atts['statistic'];
   
       $request = wp_remote_get( 'https://api.wh.geniussports.com/v1/basketball/competitions/'. $competition .'/leaders/summary?ak=eebd8ae256142ac3fd24bd2003d28782&statisticCodes='. $statisticsz .'&limit=5' );
   
       if( is_wp_error( $request )) {
   
       return false; // Bail early
   
       }
       //for-leaders
       $body = wp_remote_retrieve_body( $request );
       $data = json_decode( $body );
   
       $list = '<table class="rwd-table">'.'<tr><th>Player Name</th><th>Team</th><th>Data</th></tr>'; 
   
       if( ! empty( $data ) ) {
       $wewLeaders = $data->response;
   
       foreach($wewLeaders->data as $product ) {
   
         foreach($product->leaders as $product2 ) {
   
         //firstname-cut
         $fname = explode(' ',trim($product2->firstName));
   
         $fnamesz = strtolower($fname[0]);
   
         //lastname-capitalize;
         $lname = strtolower($product2->familyName);
   
   
       $list .='<tr><td data-th="Movie Title">'. $fnamesz .' '. $lname .'</td><td data-th="Genre">' . $product2->teamName . '</td> <td data-th="Year">' . $product2->value . '</td></tr>';
   
       }
   
       }//endforeach
   
       }// end if
   
       return $list . '</table>';
   
       }
   
       add_shortcode('test-api-leaders', 'test_api_leaders_shortcode');
       ```
   

Viewing 1 replies (of 1 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years, 10 months ago](https://wordpress.org/support/topic/transient-api-json-shortcode/#post-10575619)
 * Before you generate the output, check for the transient. If it exists, use it,
   else generate the output and set the transient.

Viewing 1 replies (of 1 total)

The topic ‘transient api json shortcode’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [json](https://wordpress.org/support/topic-tag/json/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Joy](https://wordpress.org/support/users/joyously/)
 * Last activity: [7 years, 10 months ago](https://wordpress.org/support/topic/transient-api-json-shortcode/#post-10575619)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
