-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change makes sense to me and still works as described in the original PR. I just have a question about the test.
@@ -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}} -->'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. 😅
There was a problem hiding this comment.
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.
Thanks for taking a look, @jffng! With @dlh01's help, I noticed that we no longer need the I've updated the PR to include this change, and we also need the fix for the test so it's testing with the correct markup (inherit: false). This is ready for another review 🙏 |
* Replace query_posts() with set() * Fix test_rendering_post_template_with_main_query_loop_already_started test * Remove is_singular check Co-authored-by: mikachan <[email protected]> Co-authored-by: jffng <[email protected]> Co-authored-by: David Herrera <[email protected]>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 3215aa5 |
* Replace query_posts() with set() * Fix test_rendering_post_template_with_main_query_loop_already_started test * Remove is_singular check Co-authored-by: mikachan <[email protected]> Co-authored-by: jffng <[email protected]> Co-authored-by: David Herrera <[email protected]>
I just cherry-picked this PR to the release/19.3 branch to get it included in the next release: f731ae7 |
What?
This is a follow-up to #65067 to improve the implementation of querying 'post' post types.
Why?
As
inherit
is now automatically set tofalse
when a Query Loop is inserted within content (a single post/page/CPT), we don't need to manually update the query in anis_singular()
check.Also,
query_posts()
should generally be avoided as it could cause some unwanted side effects. See this comment for more details.How?
Removes the
is_singular()
check from the Post Template server-side render, and updates thetest_rendering_post_template_with_main_query_loop_already_started
test so that it is correctly usinginherit: false
in the test block markup.Testing Instructions
test_rendering_post_template_with_main_query_loop_already_started
PHP unit test passes