[wp-hackers] identifying if a transient exists without the WordPress APIs
Haluk Karamete
halukkaramete at gmail.com
Wed Jul 8 17:02:35 UTC 2015
I've got this sorted out!
Am I missing anything?
$my_transient = 'my_transient';
$transient_timeout = '_transient_timeout_' . $my_transient;
if ( blp_get_option( $transient_timeout ) < time() ): //see the wrapper
function I included below
//all bets are off!
//the transient I'm after must have been expired or never existed to begin
with!
else:
//bingo transient is available, get it.
$value = blp_get_option( $my_transient );
endif;
// the wrapper function ( which was inspired by the get_option's guts )
function blp_get_option( $transient_name ) {
run the following SQL and return the result either FALSE or with the
matched option value
"SELECT option_value FROM `our_prefix_here_options` WHERE option_name =
'{$transient_name}' LIMIT 1";
}
On Wed, Jul 8, 2015 at 9:36 AM, Haluk Karamete <halukkaramete at gmail.com>
wrote:
> Hi guys,
>
> I know this would have been an easy one using the WordPress API's - as the
> answer to my question would be -> just use get_transient dude!
>
> But I want to figure this out with straight mysql - as I need this
> information at the mother of all pages, the index.php at the site root -
> before it has loaded the blog-header.
>
> If the name of the transient I'm after is 'my_transient', what mysql
> statement would reliably get me its contents - if 'my_transient' has not
> expired and still available?
>
> Needless to say, that SQL statement cannot tap into the wpdb APIs for the
> same very reason; WordPress has not loaded yet. So this has to be straight
> mysql solution.
>
> I know that the transients may not always be stored in the options table (
> it could be memory based ) but here we will assume that we use options
> table for that.
>
>
More information about the wp-hackers
mailing list