Codex

Function Reference/setup postdata

Contents

Description

Set up global post data.

Usage

<?php setup_postdata(); ?>

Parameters

$post
(object) (required) A post object.
Default: None


Return Values

This function always returns true.

Examples

<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :	setup_postdata($post); ?>
	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; wp_reset_postdata(); ?>
</ul>


Change Log

Source File

setup_postdata() 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.