WordPress transients 101

395 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
395
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

WordPress transients 101

  1. 1. WORDPRESSTRANSIENTS101A BASIC GUIDE TO WORDPRESSTRANSIENTSBY @CHRISAPREA
  2. 2. WHAT ARE TRANSIENTS?Transients allow you to store non timesensitive data for a specified timeperiod.After this time period has expired youwill fetch an updated version of thedata being stored.
  3. 3. PRACTICAL TRANSIENTUSAGE• Twitter / Facebook / social media feed• A popular articles widget• Recent articles widget• Non time sensitive database queries• Expensive non time sensitive PHP routines• Other non time sensitive API calls (flickr, YouTube, etc)• Instead of cron?
  4. 4. 3 FUNCTIONS TO RULE THEMALL1. get_transient()2. set_transient()3. delete_transient()
  5. 5. WHAT CAN WE STORE INTRANSIENTS?• Strings / HTML• Arrays / Objects (auto serialized)
  6. 6. TIME TO CODE  / If( false === ( $api_data = get_transient( ‘my_api_call’ ) ) ){ // generate the transient data $api_data = some_api_call(); // save the transient data set_transient( ‘api_data’, $api_data, 60 * 60 * 24 );}// do stuff with transient data ( $api_data )
  7. 7. EXAMPLE TIMEAPREA.ME/DEMOS/TRANSIENTS
  8. 8. THANKS! @CHRISAPREAAPREA.ME/DEMOS/TRANSIENTS

×