Codex

Function Reference/wp reset query

Contents

Description

This function destroys the previous query used on a custom Loop. Function should be called after The Loop to ensure conditional tags work as expected.

Usage

<?php wp_reset_query(); ?>

Parameters

This function does not accept any parameters.

Return Values

This function does not return any values.

Examples

The following example shows how to use wp_reset_query() after a custom loop

<?php
query_posts( 'posts_per_page=5' );
if ( have_posts() ) :
	while ( have_posts() ) : the_post();
		?><a href="<?php the_permalink() ?>"><?php the_title() ?></a><br /><?php
	endwhile;
endif;
wp_reset_query();
?>

Change Log

Source File

wp_reset_query() is located in wp-includes/query.php.

Related

Query Tags: WP_Query (Class), get_query_var(), query_posts(), have posts(), the_post(), rewind_posts(), wp_reset_postdata(), wp_reset_query()

See also index of Function Reference and index of Template Tags.