Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Wordpress custom query for getting information outside of The Loop
// 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();
while ($wp_query->have_posts()) : $wp_query->the_post();
// 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
You can’t perform that action at this time.