Created
April 7, 2011 19:09
-
-
Save danott/908465 to your computer and use it in GitHub Desktop.
Wordpress custom query for getting information outside of The Loop
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
<? | |
// This is a sub query for pulling data from outside of the loop.. | |
// However, we need to preserve the original $wp_query if this is inside an existing loop. | |
// If this is the last query, then you can ditch it. | |
$temp = $wp_query; | |
$wp_query = null; | |
$wp_query = new WP_Query(); | |
$wp_query->query('your-custom-query'); | |
while ($wp_query->have_posts()) : $wp_query->the_post(); | |
endwhile; | |
// if this is going before the main loop, | |
// we need to set the query back to the original. | |
// if not, ditch it. | |
$wp_query = $temp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment