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, $key, 10) ); // false when not expired $key = '1234567890123456789012345678901234567890123456'; var_dump( get_transient($key) ); // always returns false var_dump( set_transient( $key, $key, 10) ); // always true
option_name field in database is
However I absolutely can't figure out why this doesn't produce any database errors and all returns and hooks on setting transient work just fine... Except that in reality timeout option doesn't get written and it all fails miserably.
I suspect this query in
$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload ) );
Can anyone help figure out what it should do when option's name passed is too long and why it doesn't produce errors or anything?