W3cubDocs

/WordPress

the_post()

Iterate the post index in the loop.

More Information

Basic Usage

if ( have_posts() ) {
while ( have_posts() ) {

the_post(); ?>

<h2><?php the_title(); ?></h2>

<?php the_content(); ?>

<?php }
}

Source

function the_post() {
	global $wp_query;

	if ( ! isset( $wp_query ) ) {
		return;
	}

	$wp_query->the_post();
}

Changelog

Version Description
1.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/the_post