title

Don’t Break WordPress Loops

 

Don’t Break WordPress Loops

23 Oct 2013, Posted by antoine in

Multiple loops are great but can wreak havoc if not used correctly. To make sure your loop runs smoothly and you can still use all of the functions that rely on globals, store the original query in a temporary variable.

$tmp_query = $wp_query;
query_posts('cat=5&order=ASC');
while( have_posts() ) : the_post() ?>
$wpdb, the WordPress database class to query the database directly.
$recent_users = $wpdb->get_results( "SELECT display_name, user_registered FROM $wpdb->users ORDER BY user_registered DESC LIMIT 0,10" );

This class has great features and functions. Take a look at “Interacting With the WordPress Database” for an in-depth tutorial.