How can I store an image in the database with Transients API?

I’m trying to store an image generated with imagecreatefrompng() using the Transients API, but it just stores an empty string (string(0) “”). Also, I notice if I set the transient before imagedestroy( $im ), the image is broken and doesn’t display at all (broken image thumbnail). What can I store in the database with the … Read more

Transient not working for custom loops

I’m working at a WordPress theme. Since I need to display featured posts, related posts, some widgets with recent posts and so on, I need to use multiple custom loops. Because of this, the number of database queries have also increased. In an attempt to optimize the theme for better performance I came across http://codex.wordpress.org/Transients_API … Read more

Use Transient API to cache queries for all posts in all categories?

I use this to display all posts in all categories. $args_cat = array( // order by category name ascending ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, // get only top level categories ‘parent’ => 0 ); $categories = get_categories($args_cat); // Full posts query // if there are categories filled with posts if (!empty ($categories) && !is_wp_error( … Read more

Transients API and multisite

we’re using the Atlas HTML sitemap plugin, which caches the sitemap using the transients API with a call like: set_transient( ‘dmac_html_sitemap’, $output, 60*60*24*7 ); Now, we also have a multi-site setup and I was wondering where the transients are stored and if WP multisite is keeping them separate. It keeps options separate as each site(blog) … Read more

Storing an XML Response (Transient)?

Haven’t worked much with XML so I’m hitting a bit of a wall: function getapi() { $api_response = wp_remote_get( “http://example.com/getXML” ); $data = wp_remote_retrieve_body( $api_response ); $output = new SimpleXMLElement ($data ); return $output; } Get or set the Transient function transient() { $transient = get_transient( ‘transient_value’ ); if ( ! $transient ) { $transient … Read more

Long option names fail silently?

This was really driving me crazy. I was debugging some code with code-generated transient names and they were failing like crazy for no apparent reason. After much much pain and experimentation I figured out that it fails when over certain key length: $key = ‘1234567890’; var_dump( get_transient($key) ); // works just fine var_dump( set_transient( $key, … Read more