What the %$£"! are Transients

296 views

Published on

WordPress Transients - a short explaination

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
296
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

What the %$£"! are Transients

  1. 1. Hands up who has never heard ofWordPress Transients?
  2. 2. According to the codexhttp://codex.wordpress.org/Transients_API“…offers a simple and standardized way of storingcached data in the database temporarily by giving it acustom name and a timeframe after which it will expireand be deleted.”
  3. 3. You can think of transients as havingsimilar functionality to cookies.
  4. 4. There are single and multisitetransients.set_transient()get_transient()delte_transient()set_site_transient() *multisiteget_site_transient() *multisitedelte_site_transient() *multisite
  5. 5. <?php set_transient( $transient, $value, $expiration ); ?>$transient = (string) Name$value = (mixed) your value$expiration = (int) expiry in seconds(0 = never expire)Returns true if set, false if not set
  6. 6. <?php get_transient( $transient ); ?>$transient = (string) NameReturns (mixed) = the transient value or false ifit has expired and/or doesn’t exist.
  7. 7. Use transients whenever you are going to make multiple calls tobuild a list of information that you will have to output multipletimes.Use transients with external APIs and feeds.e.g. Grab your 10 latest tweets and store them in a transient.
  8. 8. Use the following method.value = get_transient(name) //get the valueIf (value) // if transient existsUse transient value e.g. output to screenElseGet the value from your sourceset_transient( name, value, expirytime)Do your stuff

×