Skip to content

Instantly share code, notes, and snippets.

@brashrebel
Created July 17, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brashrebel/f6fa0bdea46ae769f436 to your computer and use it in GitHub Desktop.
Save brashrebel/f6fa0bdea46ae769f436 to your computer and use it in GitHub Desktop.
The Loop Example
<?php
// CUSTOM QUERY
// Build the arguments for a query
$args = array(
'author' => 'kyle',
'posts_per_page' => 2,
'nopaging' => true,
);
// Create a query object
$dis_query = new WP_Query( 'posts_per_page' );
// Proceed if the query actually has something
if ( $dis_query->have_posts() ) :
// Keep doing this until there are no more entries
while ( $dis_query->have_posts() ) :
$dis_query->the_post();
the_title();
echo '<br/>';
endwhile;
endif;
// Here's a query that assumes the MAIN query
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
the_title();
the_content();
endwhile;
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment