Skip to content

Instantly share code, notes, and snippets.

@mattbanks
Created June 3, 2015 15:10
Show Gist options
  • Save mattbanks/55c990b1d5b517ccf043 to your computer and use it in GitHub Desktop.
Save mattbanks/55c990b1d5b517ccf043 to your computer and use it in GitHub Desktop.
TextExpander 5 snippet for a new WP_Query wrapped in a transient
// Get any existing copy of our transient data
if ( false === ( $%filltext:name=Query Name:default=myquery% = get_transient( '%filltext:name=Query Name:default=myquery%' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$%filltext:name=Query Name:default=myquery%_args = array(
'post_type' => '%filltext:name=Post Type:default=post%',
'order' => '%fillpopup:name=Order:default=ASC:DESC%',
'orderby' => '%fillpopup:name=Orderby:default=date:ID:rand:title:author:menu_order%',
'post_status' => 'publish',
'posts_per_page' => %filltext:name=Posts Per Page:default=-1%
);
$%filltext:name=Query Name:default=myquery% = new WP_Query( $%filltext:name=Query Name:default=myquery%_args );
set_transient( '%filltext:name=Query Name:default=myquery%', $%filltext:name=Query Name:default=myquery%, %filltext:name=Expiration (in hours):default=24% * HOUR_IN_SECONDS );
}
if ( $%filltext:name=Query Name:default=myquery%->have_posts() ) :
/* Start the Loop */
while ( $%filltext:name=Query Name:default=myquery%->have_posts() ) : $%filltext:name=Query Name:default=myquery%->the_post(); ?>
<!-- do stuff here -->
<?php endwhile;
else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif;
wp_reset_postdata(); ?>
%filltop%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment