hopefully you can help me with this scenario:
I have several queries of different post types inside shortcode function. Now I´m trying to store those queries with transients. But those transients need to have a unique name for each page from where the shortcode is called.
$trans_posts_golfcourse_ = 'trans_posts_golfcourse_'.$landingpage;
if( false === ( $$trans_posts_golfcourse_ = get_transient( 'trans_posts_golfcourse_' ) ) ) {
$args = array (
'posts_per_page'=> 5,
'post__in' => $posts_golfcourse,
'post_type' => 'golfcourse',
'post_status' => 'publish',
'cache_results' => false,
);
$$trans_posts_golfcourse_ = new WP_Query( $args );
set_transient( 'trans_posts_golfcourse_', $$trans_posts_golfcourse_, 60*60*4 );
}
The dynamically generated variable name is
$$trans_posts_golfcourse_
But how does this have to look like as a parameter?:
get_transient( 'trans_posts_golfcourse_' )
Thanks in advance!
EDIT: found solution for dynamic variable as parameter The parameter(string) has to be generated the same way as the variable name:
get_transient( 'trans_posts_golfcourse_'.$landingpage )
complete code:
$trans_posts_golfcourse_ = 'trans_posts_golfcourse_'.$landingpage;
if( false === ( ${$trans_posts_golfcourse_} = get_transient( 'trans_posts_golfcourse_'.$landingpage ) ) ) {
$args = array (
'posts_per_page'=> 5,
'post__in' => $posts_golfcourse,
'post_type' => 'golfcourse',
'post_status' => 'publish',
'cache_results' => false,
);
${$trans_posts_golfcourse_} = new WP_Query( $args );
set_transient( 'trans_posts_golfcourse_'.$landingpage, ${$trans_posts_golfcourse_}, 60*60*4 );
}
EDIT: Transient is not reducing queries, although transient seems to be called correctly. Does anybody have an idea?