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

Query Loop: Remove is_singular() check and fix test #65483

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ function render_block_core_post_template( $attributes, $content, $block ) {
if ( in_the_loop() ) {
$query = clone $wp_query;
$query->rewind_posts();

// If in a single post of any post type, default to the 'post' post type.
if ( is_singular() ) {
query_posts( array( 'post_type' => 'post' ) );
}
} else {
$query = $wp_query;
}
Expand Down
2 changes: 1 addition & 1 deletion phpunit/blocks/render-post-template-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function test_rendering_post_template_with_main_query_loop_already_starte
global $wp_query, $wp_the_query;

// Query block with post template block.
$content = '<!-- wp:query {"query":{"inherit":true}} -->';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this test need to change? Was this not testing with the correct inherit setting before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Was this not testing with the correct inherit setting before?

No 🙈 And it was passing because I was using query_posts(), which I think was replacing the global query, so anything set via the Query Loop block was ignored and wasn't truly being tested.

This test should have been updated when the changes were added for automatically setting inherit to false in the original PR. It was a complete oversight by me, although I'm glad I updated the test earlier on in the process and so I knew how to fix it. 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! Good thing you caught it early.

$content = '<!-- wp:query {"query":{"inherit":false}} -->';
$content .= '<!-- wp:post-template {"align":"wide"} -->';
$content .= '<!-- wp:post-title /-->';
$content .= '<!-- /wp:post-template -->';
Expand Down
Loading