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();
// 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;
You can’t perform that action at this time.