Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid entering The Loop when rendering Reader template #4185

Merged
merged 1 commit into from
Jan 27, 2020

Conversation

westonruter
Copy link
Member

Summary

This fixes an issue that was uncovered by @jackmcconnell in #1780 (comment).

If an overridden Reader mode template attempted to use The Loop to render the title or content, for example:

<?php if ( have_posts() ) : ?>
	<?php while ( have_posts() ) : the_post(); ?>
		<?php the_content(); ?>
	<?php endwhile; ?>
<?php endif; ?>

This would result in nothing being output because reader-template-loader.php was entering The Loop via the_post(). Since only one post is in The Loop in singular queries, the result was that have_posts() would return false and nothing would be output.

The fix is simply to directly populate the $post global and set up its global variables without advancing the current_post in the global WP_Query.

This fixes a regression that was introduced in #3781.

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@westonruter westonruter added the Bug Something isn't working label Jan 27, 2020
@westonruter westonruter added this to the v1.5 milestone Jan 27, 2020
@googlebot googlebot added the cla: yes Signed the Google CLA label Jan 27, 2020
@westonruter
Copy link
Member Author

Build for testing: amp.zip (1.5.0-alpha-20200127T052304Z-584559dd7)

Copy link
Contributor

@pierlon pierlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issue to report, LGTM.

@westonruter westonruter merged commit 1a130cf into develop Jan 27, 2020
@westonruter westonruter deleted the fix/the-loop-in-reader-template branch January 27, 2020 15:50
@csossi
Copy link

csossi commented Feb 13, 2020

CAn you add QA instructions, @pierlon ?

@westonruter
Copy link
Member Author

This needs developer QA. As long as @pierlon confirmed the right behavior, this can move to Done.

@csossi
Copy link

csossi commented Feb 13, 2020

thanks, @westonruter !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants