Skip to content

Instantly share code, notes, and snippets.

@timiwahalahti
Created April 1, 2016 10:01
Show Gist options
  • Save timiwahalahti/a362281fe9724c7c334ebc24ed67ecb8 to your computer and use it in GitHub Desktop.
Save timiwahalahti/a362281fe9724c7c334ebc24ed67ecb8 to your computer and use it in GitHub Desktop.
Atom snippet for basic WP_Query
'.source.php':
'WP_Query (simple args)':
'prefix': 'wpquery'
'body': """
$args = array(
'author' => 1,
'author__in' => array( 1 ),
'cat' => 5,
'category__in' => array( 2, 6 ),
'tag_id' => 5,
'tag__in' => array( 2, 6),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'color',
'field' => 'slug',
'terms' => array( 'red', 'blue' ),
'include_children' => true,
'operator' => 'IN'
),
),
'p' => 1,
'page_id' => 1,
'post_parent' => 1,
'post_parent__in' => array( 1, 2, 3 ),
'post__in' => array( 1, 2, 3 ),
'post_type' => any,
'post_status' => 'any',
'posts_per_page' => 10,
'posts_per_archive_page' => 10,
'offset' => 3,
'order' => 'DESC',
'orderby' => 'date',
'meta_key' => 'key',
'meta_value' => 'value',
'meta_compare' => '=',
'meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'type' => 'CHAR',
'compare' => '=',
),
),
);
$the_query = new WP_Query( $args );
// The Loop
if( $the_query->have_posts() ):
while( $the_query->have_posts() ):
$the_query->the_post();
// Do Stuff
endwhile;
endif;
// Reset Post Data
wp_reset_postdata();
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment