• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Using WordPress Transients For Caching

By Abhishek Ghosh December 14, 2013 5:02 am Updated on December 14, 2013

Using WordPress Transients For Caching

Advertisement

Using WordPress Transients for caching demands no extra paid WordPress Plugins – you can simply add few lines of PHP codes to cache certain queries. We have written about WordPress Transients in quite good details. That article is a minimum need to understand what we are going to write in this article.

 

WordPress 3.8 and Using WordPress Transients For Caching

 

As practically you can see, WordPress 3.8 has been visually and on coding has changed a huge, the default free theme can easily compete with a very nicely coded paid Theme. With time, it is more likely that the market of premium WordPress Themes will not exist anymore. The reason of existing premium WordPress Themes is because of the Framework – like provided by Genesis or Thesis. With time, the distance will gradually decrease and all of the advanced users need to understand the basics of how a Child Theme can be created. You can search on this website for the same. We want to avoid becoming offtopic and remain on the point – Using WordPress Transients For Caching.

The basic advantage of the situation of using an universal Theme Framework is the ability to share and use the required codes, snippets from and with a large number of users. With time, WordPress community really took important steps for making WordPress dot ORG better – it is not that easy to understand, unless one is related to Core Development of WordPress.

Advertisement

---

With many plugin, software generated WordPress Themes; the functions.php of the current Theme or Child Theme might not work properly in the way we want.

 

Using WordPress Transients For Caching

 

Many theoretical things are written, but without practical working example on how on using WordPress Transients for Caching, practically the sayings are valueless for a relatively new to WordPress user. Example can be :

Vim
1
2
3
4
5
6
$transient_key = 'my-transient-key';
$data = get_transient( $transient_key );
if ( $data == '' ) {
$data = get_posts( array( 'posts_per_page' => -1 ) );
set_transient( $transient_key, $data, 60 * 60 * 24 );
}

If one add these snippets after changing the example values like my-transient-key on Theme’s or child Theme’s functions.php file, they will override any cache plugin settings. You need to adjust or fully deactivate some plugin to avoid a kind of conflict out of double caching. Now, in a WordPress Web Page, what usually we have ‘changing’ values ? You can think about the widgets – Google Plus or Twitter on this website. Within one hour, the change of followers really does not matter much. Recent Post really do not change hourly, unless new post is published.

Using WordPress Transients For Caching

We have forgotten who originally wrote this snippet for Twitter, but this a great example for using WordPress Transients :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function my_followers_count($screen_name = 'user-name'){
$key = 'my_followers_count_' . $screen_name;
// Seek for a cached version
$followers_count = get_transient($key);
if ($followers_count !== false)
return $followers_count;
else
{
// Send query to Twitter,
// depreciated old API used for example, refer to API 1.1 docs from Twitter
$response = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name={$screen_name}");
if (is_wp_error($response))
{
// In case Twitter Server is down
return get_option($key);
}
else
{
// Parse the body and json_decode it
$json = json_decode(wp_remote_retrieve_body($response));
$count = $json->followers_count;
// Store the result in a transient
set_transient($key, $count, 60*60*24);
update_option($key, $count);
return $count;
}
}
}

We have used the PHP snippet without normal indentation, one can add indentation for cleaner coding.

This Article Has Been Shared 239 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Using WordPress Transients For Caching

  • Scalable MySQL Database for WordPress with Rackspace Cloud

    Scalable MySQL Database for WordPress is very easy to create as Rackspace allows Cloud Database,so does Amazon. Here is a guide for high performance WordPress.

  • Adding Schema.org Structured Data in Genesis Theme

    Adding Schema.org Structured Data in Genesis Theme without using any plugin is quite easy as Genesis has great documentation and has excellent existing markups.

  • Schema.org for WordPress : Advanced Tips for Genesis 2.0

    Schema.org for WordPress is nicely integrated by Genesis 2.0 but in terms of semantic complexity, it requires some advanced hand made tweaking.

  • WordPress Post to Downloadable PDF, Text : Practical Options

    WordPress Post to downloadable PDF, Text has many points to consider when we will think about the usability, SEO, HTML5 and Schema.org markups.

  • Why schema.org Official Website Has No itemscope and itemtype Schema

    Why schema.org Official Website Has No itemscope and itemtype Schema? Have you ever noticed this small point?

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (20K Followers)
  • Twitter (4.9k Followers)
  • Facebook (5.8k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.2k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Wi-Fi for Old House With Thick Walls January 26, 2021
  • What is Inertial Navigation System? January 25, 2021
  • What is Miniaturization? January 24, 2021
  • What is Domain-Driven Design (DDD)? January 23, 2021
  • Top 10 Anti Hacking Software for Microsoft Windows January 22, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Using WordPress Transients For Caching," in The Customize Windows, December 14, 2013, January 27, 2021, https://thecustomizewindows.com/2013/12/using-wordpress-transients-for-caching/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy