{"id":18626,"date":"2021-01-11T17:00:49","date_gmt":"2021-01-11T16:00:49","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=18626"},"modified":"2021-01-11T14:19:19","modified_gmt":"2021-01-11T13:19:19","slug":"wordpress-transients","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/wordpress-transients\/","title":{"rendered":"What Are WordPress Transients and How to Manage Them"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]Everyone wants your website to run a bit faster. You want it because you\u2019re losing visitors to slow loading times. The visitors want it because otherwise, they\u2019ll have to do another search and they just did one. Search engines want it because they\u2019re into delivering the best possible experience to the searchers, so your sluggish website is cramping their style, too.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]One of the ways to speed up a website is to cache some data in a handy place where it can easily be accessed thus dampening the impact of these requests on your server. You can do it with <a href=\"https:\/\/qodeinteractive.com\/magazine\/best-wordpress-caching-plugins\/\">caching plugins<\/a>, but before you do, it might not hurt to learn a thing or two about WordPress transients.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In this article, we\u2019ll explain:<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#what-are-wordpress-transients\">What Are WordPress Transients<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#when-should-you-use-them\">When Should You Use Them<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#basic-operations-using-transients\">Basic Operations Using Transients<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#how-to-manage-them\">How to Manage Them<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;80px&#8221;][vc_widget_sidebar sidebar_id=&#8221;new-top-picks-banner&#8221;][vc_empty_space height=&#8221;81px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"what-are-wordpress-transients\"><\/a>What Are WordPress Transients?<\/h2>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;24px&#8221;]<div class=\"qodef-single-image-holder    \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"553\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/What-Are-WordPress-Transients.jpg\" class=\"attachment-full size-full\" alt=\"What Are WordPress Transients\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/What-Are-WordPress-Transients.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/What-Are-WordPress-Transients-300x171.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/What-Are-WordPress-Transients-768x438.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/What-Are-WordPress-Transients-620x354.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>Transients are types of cached data enabled in WordPress by the Transients API<\/strong>. You can use the transient to store data, but only for a while \u2013 <strong>a transient will have an expiration date after which you won\u2019t be able to access the data<\/strong>. So, transients are a type of temporary data cache.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>A transient will consist of three parts:<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><strong>Its name or key<\/strong> ($transient) \u2013 a string used to identify the transient.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><strong>The information<\/strong> ($value) \u2013 an object, array, number, or a string that\u2019s the information retrieved by the API.<\/span>        <\/div>\n            <\/li>\n<\/ul><ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><strong>Expiration<\/strong> ($expiration) \u2013 the maximum period for which the transient is valid to stay in the database.<\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Transients might seem similar to cookies, but they\u2019re different in several ways. Not only that they\u2019re stored in the database and not the visitors\u2019 browsers, but transients are much more powerful than cookies.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Transients are also tricky to handle in a couple of ways. For one, <strong>they are routinely stored in fast memory instead of the database by caching plugins, making them more difficult to locate.<\/strong> Next, they can expire at any time &#8211; <strong>the expiration date you set really is the maximum time they\u2019ll be valid for.<\/strong> Finally, even when they expire, transients are not deleted &#8211; <strong>they are either deleted when someone tries to access the information in an expired transient, or by you manually.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"when-should-you-use-them\"><\/a>When Should You Use Them?<\/h2>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;24px&#8221;]<div class=\"qodef-single-image-holder    \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"553\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/When-Should-You-Use-Them.jpg\" class=\"attachment-full size-full\" alt=\"What Are WordPress Transients\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/When-Should-You-Use-Them.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/When-Should-You-Use-Them-300x171.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/When-Should-You-Use-Them-768x438.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/When-Should-You-Use-Them-620x354.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>The most common use case for transients is resource-intensive queries.<\/strong> For example, multiple users asking the same database-intensive query at the same time can put a serious dent in the website\u2019s performance. But with a transient, <strong>the data they\u2019re looking for can be cached temporarily, and the whole expensive process can only be instigated if someone tries to retrieve data from a transient that expired.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Transients have found a use in other areas, too. They\u2019re commonly used for sidebar widgets that display the number of visitors, tweets, or a photostream. They\u2019re very useful when you want to get data from an external source such as Twitter or Facebook. <strong>Whenever you\u2019re operating with data you\u2019re fine with disappearing at any time, probably because you have a way to fetch it again, transients are a good choice.<\/strong> For permanent data storage, use Options.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"basic-operations-using-transients\"><\/a>Basic Operations Using Transients<\/h2>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;24px&#8221;]<div class=\"qodef-single-image-holder    \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"553\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Basic-Operations-Using-Transients.jpg\" class=\"attachment-full size-full\" alt=\"Basic Operations Using Transients\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Basic-Operations-Using-Transients.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Basic-Operations-Using-Transients-300x171.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Basic-Operations-Using-Transients-768x438.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Basic-Operations-Using-Transients-620x354.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]You can do three things to transients. <strong>First, you must save the transient.<\/strong> Usually, it will go to the database, but remember, it might end up in the fast memory. To save a transient, you should use the following syntax:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">set_transient( $transient, $value, $expiration );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Just remember to replace the appropriate values with real ones.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>Next, you can fetch a transient you\u2019ve saved using the following syntax:<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">get_transient ( $transient );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]You\u2019ll only need the transient key for this, and you\u2019ll only get an answer if the transient hasn\u2019t expired yet. If it has, you will get a false value.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>Finally, you can delete the transient even before it has expired.<\/strong> To do so, you\u2019ll have to use the syntax:[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">delete_transient ( $transient );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]This will remove the transient. <strong>As you might have noticed, transient names are very important, so make sure you have a naming system in place.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\"><a id=\"how-to-manage-them\"><\/a>How to Manage Transients<\/h2>\n<p>[\/vc_column_text][vc_column_text]If you want a more convenient way to manage your transients, you can download and install the <a href=\"https:\/\/wordpress.org\/plugins\/transients-manager\/\" target=\"_blank\" rel=\"noopener\">Transients Manager<\/a> plugin.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Transients-Manager.jpg\" class=\"attachment-full size-full\" alt=\"Transients Manager\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Transients-Manager.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Transients-Manager-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Transients-Manager-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Transients-Manager-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]After activating it, you can head over to <em><strong>Tools &gt; Transients<\/strong><\/em>, and there you can find a full list of transients, including their names, values, and expiration dates.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Transients.jpg\" class=\"attachment-full size-full\" alt=\"All Transients\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Transients.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Transients-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Transients-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/All-Transients-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]The plugin will give you several options for deleting transients in bulk \u2013 <strong>you can delete all of them, the ones that expired, or the ones with an expiration date.<\/strong> Keep in mind that it\u2019s always a good idea to delete expired transients. <strong>You can also delete the transients separately, and you can edit their names, values, and expiration dates, too.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"518\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Edit-Transients.jpg\" class=\"attachment-full size-full\" alt=\"Edit Transients\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Edit-Transients.jpg 969w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Edit-Transients-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Edit-Transients-768x411.jpg 768w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2021\/01\/Edit-Transients-620x331.jpg 620w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;78px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Let\u2019s Wrap It Up<\/h2>\n<p>[\/vc_column_text][vc_column_text]In the never-ending quest to make your website faster, you can use every ally you can find. Transients are among the better ones, even though they\u2019re sometimes overlooked. But the more you learn about them, the things they can do and the tricks you can pull off with them, you\u2019ll get more and more interested in using them and they\u2019ll become more and more useful.<br \/>\n[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Need some help managing WordPress transients on your website? We&#8217;ll help show you what they are, how to use them, and what are the best ways to manage them. <\/p>\n","protected":false},"author":9295,"featured_media":18693,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[4,13],"class_list":["post-18626","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resources","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/18626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/9295"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=18626"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/18626\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/18693"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=18626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=18626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=18626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}