WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the Transients API to hold the output for a gallery plugin's shortcode I created. Due to the number of images used and different layouts needed, the transient name looks lik the following:


So - the int portion is the post ID it is referencing and the five is this specific shortcode's column setting. Where I'm running into trouble is flushing these shortcodes on-save of the referenced galleries.

What I'd normally do is something like following:

function galleries_delete_transient($post_id) {
    switch (get_post_type()) {
        case 'galleries':

The problem being here is that the column setting can be different based on a certain page's needs - so I was wondering if there is any type of wildcard I can use here to make this a bit more dynamic (to just clear all of them - something like delete_transient('galleries_single_shortcode_'.$post_id%);). Any help would be greatly appreciated. Thanks!


Complete shortcode function added for clarity how everything is constructed:

function galleries_single_shortcode($atts, $content = null) {
            "id"     => '',
            "columns" => 'four'
    ), $atts));

    global $galleries_options;

    $galleries_single_shortcode_output = get_transient('galleries_single_shortcode_'.$id.$columns);
    if ($galleries_single_shortcode_output === false) {


        // OUTPUT HERE

        $galleries_single_shortcode_output = ob_get_contents();


        set_transient('galleries_single_shortcode_'.$id.$columns, $galleries_single_shortcode_output, 60 * 60 * 24);


    return $galleries_single_shortcode_output;
add_shortcode('galleries_single', 'galleries_single_shortcode');
share|improve this question
How do you determine the number of columns? Asked another way: how do you determine/construct the correct transient name? Knowing that method would help answer the question. – Chip Bennett Nov 19 '12 at 13:57
Hi @ChipBennett - added the wrapper function around the shortcode for clarity - in essence, manually added by the user [galleries_single id=123 columns=four]. Thanks! – Zach Nov 19 '12 at 14:07
Why are you saving the column setting as part of the transient key instead of as part of the data? – s_ha_dum Nov 19 '12 at 14:43
@s_ha_dum So if the user calls the same gallery on two different pages, but needs different column settings there won't be any conflicts and they are kept unique – Zach Nov 19 '12 at 14:52
I don't think the transients function accepts wildcards. It would be something like delete_transient('galleries_single_shortcode_'.$post_id.'%%');) if it did, though. I assume you've tested that. – s_ha_dum Nov 19 '12 at 15:09
up vote 3 down vote accepted

Forgot I could go this route:

$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_galleries_%')" );
share|improve this answer
While this works for you it's important to note that this won't work for everybody. If you're using memcache (or similar), transients are not stored in the database. – Matthew Boynes Feb 20 '13 at 23:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.