This repository was archived by the owner on Sep 27, 2023. It is now read-only.
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
Open
Description
It seems like setup_postdata()
does not work correctly if we does not use a global $post
.
For instance:
The output will be correct when using this:
foreach ( (array) $featured_posts as $post ) :
setup_postdata( $post );
get_template_part( 'content', 'featured-post' );
endforeach;
wp_reset_postdata();
The output will be not correct when using this:
foreach ( (array) $featured_posts as $featured_post ) :
setup_postdata( $featured_post );
get_template_part( 'content', 'featured-post' );
endforeach;
wp_reset_postdata();
Example of using setup_postdata()
with $post
: https://github.com/WordPress/WordPress/blob/master/wp-content/themes/twentyfourteen/featured-content.php#L23
When using $post
, the displays the following error: "Overriding WordPress globals is prohibited. Found assignment to $post".
What would you recommend in this case to avoid the error? Are we allowed to use setup_postdata()
?