8000 setup_postdata() and global $post · Issue #177 · WPTT/theme-sniffer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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.
setup_postdata() and global $post #177
Open
@dashkevych

Description

@dashkevych

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()?

Metadata

Metadata

Assignees

Labels

Type: QuestionThis is a question regarding the functionality of the plugin.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0