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 Block: Fix 'parents' argument validation #68983

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

Mamaduka
Copy link
Member

What?

Part of #68620

PR updates Query parents argument validation for hierarchical post types to allow querying only top-level entries, using "parents":[0].

Why?

  • A zero is a valid parent ID for hierarchical post types. Used to display top-level items.
  • Helps developers provide custom query patterns that only display top-level pages.

Testing Instructions

  1. Ensure you have a couple of pages with and without parents.
  2. Create a page.
  3. Add a Test Query using the code editor.
  4. Confirm that the Query block displays only the top-level items.

Testing Instructions for Keyboard

Same.

Test Query

Markup

<!-- wp:query {"queryId":1,"query":{"perPage":10,"pages":0,"offset":0,"postType":"page","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[0],"format":[]}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title /-->

<!-- wp:post-date /-->
<!-- /wp:post-template -->

<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->

<!-- wp:query-pagination-numbers /-->

<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->

<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:query -->

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Block] Query Loop Affects the Query Loop Block labels Jan 31, 2025
@Mamaduka Mamaduka self-assigned this Jan 31, 2025
Copy link

Flaky tests detected in ae0aa39.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13071058461
📝 Reported issues:

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

The code looks good to me, but do we need to submit a PR against core along with this PR? This line.

Copy link

github-actions bot commented Feb 1, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka
Copy link
Member Author

Mamaduka commented Feb 1, 2025

The code looks good to me, but do we need to submit a PR against core along with this PR?

Yes. Didn't have time to create backport PR yesterday. Will do it Monday.

@Mamaduka Mamaduka force-pushed the fix/query-loop-parents-argument-validation branch from ae0aa39 to b09fe7d Compare February 3, 2025 15:03
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@Mamaduka Mamaduka merged commit 06379a3 into trunk Feb 4, 2025
65 checks passed
@Mamaduka Mamaduka deleted the fix/query-loop-parents-argument-validation branch February 4, 2025 05:10
@github-actions github-actions bot added this to the Gutenberg 20.3 milestone Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging this pull request may close these issues.

2 participants