Skip to content

Instantly share code, notes, and snippets.

@markreale
Last active October 5, 2015 17:07
Show Gist options
  • Save markreale/2841364 to your computer and use it in GitHub Desktop.
Save markreale/2841364 to your computer and use it in GitHub Desktop.
A Full WordPress Query
<?php
// Gather all of the parameters / filters to be used in your database query as an array of arguments
$args = array(
'post_type' => 'page',
'page_id' => '2064',
'posts_per_page' => '1',
'cat' => '7',
'offset' => '7',
'paged' => '7',
'orderby' => 'rand',
'meta_query' => array(
array(
'key' => 'meta_key',
'value' => 'meta_value'
)
)
);
// Run query_posts function with your array of arguments
query_posts($args);
// Conditionally display post content (based on whether or not your query returned any posts
if(have_posts()):
// While posts were returned, iterate through them all
while(have_posts()):
// Load up the each individual post object
the_post();
?>
<!-- Display your post content -->
<?php endwhile; ?>
<!-- Display alternate content if there was no post to display -->
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment