Last active
October 5, 2015 17:07
-
-
Save markreale/2841364 to your computer and use it in GitHub Desktop.
A Full WordPress Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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