• 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 551 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, 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

Get new posts by email:

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 (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • What is an Automatic Ethanol Fireplace February 8, 2023
  • Disadvantages of Cloud-Native Computing February 7, 2023
  • Projector Screen Basics February 6, 2023
  • What is Configuration Management February 5, 2023
  • What is ChatGPT? February 3, 2023

About This Article

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

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

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

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

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

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT