Uses
Uses | Description |
---|---|
wp-includes/class-wp-query.php: WP_Query::setup_postdata() | Set up global post data. |
Set up global post data.
(bool) True when finished.
Sets up global post data. Helps to format custom query results for using Template tags.
setup_postdata() fills the global variables $id
, $authordata
, $currentday
, $currentmonth
, $page
, $pages
, $multipage
, $more
, $numpages
, which help many Template Tags work in the current post context.
setup_postdata()
does not assign the global $post
variable so it’s important that you do this yourself. Failure to do so will cause problems with any hooks that use any of the above globals in conjunction with the $post
global, as they will refer to separate entities.
<?php global $post; // modify the $post variable with the post data you want. Note that this variable must have this name! setup_postdata( $post ); ?>
File: wp-includes/query.php
function setup_postdata( $post ) { global $wp_query; if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { return $wp_query->setup_postdata( $post ); } return false; }
Version | Description |
---|---|
4.4.0 | Added the ability to pass a post ID to $post . |
1.5.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/setup_postdata